Here is the code (works with masm64)
include \masm64\include64\masm64rt.inc ; библиотеки
count PROTO arg_a:QWORD,arg_b:QWORD,arg_c:QWORD,arg_d:QWORD, arg_e:QWORD,arg_f:QWORD
.data
_a1 dq 2
_b1 dq 4
_c1 dq 2
_d1 dq 2
_e1 dq 2
_f1 dq 8
_res1 dq 0
_title db "Лаб.1-2. Процедуры. masm64",0
strbuf dq ?,0
_text db "Уравнение f/e — b/d – a/c",0ah,"Результат: %d",10,"Адрес переменной в памяти: %p",0ah,0ah,
"Автор: Неопознанный пингвин",0
.code
count proc arg_a:QWORD, arg_b:QWORD,arg_c:QWORD, arg_d:QWORD, arg_e:QWORD, arg_f:QWORD ; переносим параметри, как аргументи функции
mov rax,arg_f ; f->rax
div arg_c ; f/e
mov rbx,rax ; f/e->rbx
xor rax,rax ; rax=0
mov rax,rdx ; b->rax
div arg_d ; b/d
sub rbx,rax ; (f/e)-(b/d)
xor rax,rax ; rax=0
mov rax,rcx ; a->rax
div arg_c ; a/c
sub rbx,rax ; (f/e)-(b/d)-(a/c)
mov _res1,rbx ; содержимое rax в _res1
ret
count endp
entry_point proc
invoke count,_a1,_b1,_c1,_d1,_e1,_f1
invoke wsprintf,ADDR strbuf,ADDR _text,_res1,ADDR _res1
invoke MessageBox,0,addr strbuf, addr _title, MB_ICONINFORMATION
invoke ExitProcess,0
entry_point endp
The program works in a following way: it solves the mathematical problem f/e — b/d – a/c and sends the result into message box, but it doesn't work. it normally works without invoke count, but i need this part of code. how can i fix it?
CodePudding user response:
strbuf dq ?,0 ;only 8 byte long for output
Your destination buffer is too small. You need define large byte area for result of wsprint function. For example
strbuf db 512 dup(?)
CodePudding user response:
Your count proc has 6 args but the code only uses 3 of them! The comments don't match the instructions. You don't calculate f/e — b/d – a/c
.
See if next code displays the result:
mov rax, _f1 ; f -> rax
div _e1 ; f/e
mov rcx, rax ; f/e -> rcx
mov rax, _b1 ; b -> rax
div _d1 ; b/d
sub rcx, rax ; (f/e)-(b/d)
mov rax, _a1 ; a -> rax
div _c1 ; a/c
sub rcx, rax ; (f/e)-(b/d)-(a/c)
mov _res1, rcx
invoke wsprintf, ADDR strbuf, ADDR _text, _res1, ADDR _res1
invoke MessageBox, 0, addr strbuf, addr _title, MB_ICONINFORMATION
invoke ExitProcess, 0
Does invoke
take care of cleaning the stack in invoke count, _a1, _b1, _c1, _d1, _e1, _f1
? Or should you have written ret 48
?