Question

I'm trying to solve an equation. I'm using MASM32. I think that I'm using the correct code. But I am getting "greater" value even when I'm using necessary values to solve the equation. What am I missing or doing wrong?

.386
.model flat, stdcall 
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


.data
blogas_a db "OK",0
a_value dw 6   
a_min dw 1     
a_max dw 7



blogas_b db "less",0
b_value dw -9  
b_min dw -10
b_max dw 19

blogas_c db "greater",0
c_value dw 2
c_min dw -3
c_max dw 27

.code
start:
;________1 lygtis______a-b*c+2*a=36____________________________
_check1:
mov ax, [a_value]
push ax

mov ax, [b_value]
mov bx, [c_value]
mul bx
push ax

mov ax, 2
mov bx, [a_value]
mul bx
push ax

pop ax
pop bx
add ax, bx
pop bx
sub bx, ax

cmp ax, 36
je _outOfRange
jg _outOfRange2
jl _outOfRange3
;_____________________________________
_outOfRange: invoke StdOut, addr blogas_a
JMP _exit
_outOfRange3: invoke StdOut, addr blogas_c
JMP _exit
_outOfRange2: invoke StdOut, addr blogas_b
_exit: invoke ExitProcess, 0
end start
Was it helpful?

Solution

sub bx, ax will modify bx, and ax will remain as it was. You're probably looking for sub ax, bx instead.


Edit: You're computing a different equation than your comment suggests. Your code pushes the following values to the stack:

a
b * c
a * 2

and pops them to perform the following math (after applying the change I suggested above):

(a * 2) + (b * c) - (a)

You need to modify the math you're performing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top