I have a program that solves a math problem 5 times with different values using a loop. It stores the result in result
array, so in the end I need to show these values each starting from a new line:
result[0]
result[4]
result[8]
result[12]
result[16]
But I don't seem to understand how to implement this in my code, all methods I tried did not work. Right now it just shows 1 result. I understand, that a way to start a new line is ,10
, but I just don't know where to put it right.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
titletext db 'Лаб 5', 0
AnswerTxt db 'The answer is '
AnswerNum db 11 dup(0)
num_a dd 5,-5,-25,25,-5
num_b dd 5,32,3,-5,6
num_c dd 10,2,8,12,4
bracket dd ?
result dd ?,?,?,?,?
.code
start:
mov esi, 5
mov edi, 0
.Repeat
mov eax, -25
mov ebx, num_a[edi]
cdq
idiv ebx
add eax, num_c[edi]
mov bracket, eax
mov eax, num_b[edi]
mov ebx, num_a[edi]
cdq
imul ebx
sub bracket, eax
mov eax, num_c[edi]
mov ebx, num_b[edi]
cdq
imul ebx
mov ebx, 2
cdq
idiv ebx
add eax, 1
mov ebx, bracket
cdq
imul ebx
mov result[edi], eax
mov ebx, 2
cdq
idiv ebx
.IF edx == 0
mov eax, result[edi]
mov ebx, 2
cdq
idiv ebx
.ELSE
mov eax, result[edi]
mov ebx, 5
cdq
imul ebx
.ENDIF
mov result[edi], eax
add edi, 4
dec esi
.Until Zero?
push offset AnswerNum
push result[12]
call dwtoa
push 0
push offset titletext
push offset AnswerTxt
push 0
call MessageBox
call ExitProcess
end start
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
titletext db 'Лаб 5',0
frmt db '1 = %d',10
db '2 = %d',10
db '3 = %d',10
db '4 = %d',10
db '5 = %d',0
buff db 256 dup (0)
result dd ?,?,?,?,?
and after filling the result[0],result[4],result[8],result[12],result[16]
array:
invoke wsprintf,addr buff,addr frmt,result[0],result[4],result[8],result[12],result[16]
invoke MessageBox,0,addr buff,addr titletext,MB_OK
invoke ExitProcess,0
end start
also you can use crt_sprintf function, it is even a little bit more flexible enabling to use floats.