Reputation: 47
I tried to output structs that less than entered value, but it either print all structs or print nothing. I initialize some structs (in my case 3 objects), then enter value from keyboard, convert it to asm number, but when I compare values in procedure from struct with this number I don't get correct answer.
Here is the code:
.686
.model flat, stdcall
option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\masm32.inc
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib
includeLib C:\masm32\lib\masm32.lib
Good STRUCT
Abbr BYTE 20 DUP(?)
Descr BYTE 20 DUP(?)
Price DWORD ?
Count DWORD ?
Good ENDS
PrintGoods PROTO ptrGood:PTR Good
.data
sConsTitle BYTE "Lab rab 5", 0
strTask BYTE "Output list of goods that lower then entered price", 0Dh, 0Ah, 0Ah, 0h
sPrompt BYTE "Enter price", 0Dh, 0Ah, 0h
clrt BYTE 0Ah, 0Dh, 0
comma BYTE ", ", 0
buffer BYTE 20 DUP(0)
good_1 Good <"q", "g", 1600, 13>
good_2 Good <"w", "m", 800, 24>
good_3 Good <"e", "s", 250, 24>
.data?
hStdin DWORD ?
priceToComp DWORD ?
.code
main PROC
invoke SetConsoleTitle, addr sConsTitle
invoke StdOut, addr strTask
invoke StdOut, offset sPrompt
invoke StdIn, offset buffer, lengthof buffer
invoke atol, addr buffer
mov DWORD PTR priceToComp, eax
invoke PrintGoods, addr good_1
invoke PrintGoods, addr good_2
invoke PrintGoods, addr good_3
invoke Sleep, INFINITE
invoke ExitProcess, NULL
main ENDP
PrintGoods PROC ptrGood:PTR Good
mov eax, priceToComp
cmp eax, Good.Price
jg m1
jmp exit
m1:
mov ebx, ptrGood
invoke StdOut, ebx
invoke StdOut, addr comma
add ebx, SIZEOF Good.Abbr
invoke StdOut, ebx
invoke StdOut, addr comma
add ebx, sizeof Good.Descr
invoke ltoa, [ebx], addr buffer
invoke StdOut, addr buffer
invoke StdOut, addr comma
add ebx, sizeof Good.Price
invoke ltoa, [ebx], addr buffer
invoke StdOut, addr buffer
invoke StdOut, addr clrt
exit:
ret
PrintGoods ENDP
END main
Upvotes: 0
Views: 40