My edx is recieving garbage instead of the inputted value.
I am just doing a small comparison program where the user inputs two numbers and is displayed a message of "> or < or =".
*******code*******************
TITLE GreaterThan
INCLUDE IRVINE32.inc
.code
X BYTE ?
Y BYTE ?
Z BYTE ?
mes1 BYTE "Enter X: ",0
mes2 BYTE "Enter Y: ",0
mes3 byte " is > than ",0
mes4 byte " is < than ",0
mes5 byte " is = to ",0
.code
MAIN PROC
mov al, 0
mov edx, offset mes1
call writestring
call crlf
call readint
mov edx,offset mes2
call writestring
call crlf
call readint
call DumpRegs
mov al,x
.if al>Y
mov al,X
mov edx, offset mes3
call writedec
call writestring
mov al,Y
call writedec
call crlf
.elseif y>al
mov al,Y
mov edx, offset mes4
call writedec
call writestring
mov al,X
call writedec
call crlf
.else
mov al,Y
mov edx, offset mes5
call writedec
call writestring
mov al,X
call writedec
call crlf
.endif
MAIN ENDP
END MAIN
Now I am getting a problem with last line statement. The statement that involves the "END MAIN", sorry for the noob question...
***********************Code*********************************
TITLE GreaterThan
INCLUDE IRVINE32.inc
.code
X BYTE ?
Y BYTE ?
Z BYTE ?
mes1 BYTE "Enter X: ",0
mes2 BYTE "Enter Y: ",0
mes3 byte " is > than ",0
mes4 byte " is < than ",0
mes5 byte " is = to ",0
.code
main PROC
mov al, 0
mov edx, offset mes1
call writestring
call crlf
call readint
mov edx,offset mes2
call writestring
call crlf
call readint
call NumberH
call DumpRegs
main ENDP
NumberH PROC
mov al,x
.if al>Y
mov al,X
mov edx, offset mes3
call writedec
call writestring
mov al,Y
call writedec
call crlf
.elseif y>al
mov al,Y
mov edx, offset mes4
call writedec
call writestring
mov al,X
call writedec
call crlf
.else
mov al,Y
mov edx, offset mes5
call writedec
call writestring
mov al,X
call writedec
call crlf
.endif
ret
END NumberH
EXIT
END main
:(
END NumberH
EXIT
END main
:bg
;----------------------
main PROC
;code
exit
main ENDP
;----------------------
NumberH PROC
;code
ret
NumberH ENDP
;----------------------
END main
You need this:
X dd ? ;<<<<<<<<< DWORD not byte ! ...
Y dd ?
Z dd ?
main PROC
mov al, 0
mov edx, offset mes1
call writestring
call crlf
call readint
mov X, eax ;<<<<<<<<<<<<<<<<<<<<<<<<
mov edx,offset mes2
call writestring
call crlf
call readint
mov Y, eax ;<<<<<<<<<<<<<<<<<<<<<<<<
call NumberH
call DumpRegs
main ENDP
and changes in NumberH
Rui - don't forget "exit" at the end of main :P
Your EXIT is in wrong place and look the diference betwen ENDP and END.
Irvine uses dword to ReadInt procedure, and you are not saving the returned value in some variable like Sr RuiLoureiro says.
INCLUDE IRVINE32.inc
.code ;here is .data and not .code
X BYTE ?
.code
MAIN PROC
mov al, 0 ;you don't need this line
In your NumberH procedure, you are inserting so much code that do the same thing, you can write it smaller, so your final program stay smaller.
To compare numbers that are the same using IF statement, you can use a double equal signal "==". Like "If eax == Y".
NumberH PROC
mov eax,X
.if eax>Y
mov edx, offset mes3
.elseif eax<Y
mov edx, offset mes4
.else ;elseif eax==Y
mov edx, offset mes5
.endif
call writedec
call writestring
mov eax,Y
call writedec
call crlf
ret
NumberH ENDP
Quote from: dedndave on May 06, 2011, 04:40:14 PM
Rui - don't forget "exit" at the end of main :P
Yes dave ! He need to learn ... :green2
Dont forget call WaitMsg before EXIT
Quote from: dedndave on May 06, 2011, 04:00:10 AM
:(
END NumberH
EXIT
END main
:bg
;----------------------
main PROC
;code
exit
main ENDP
;----------------------
NumberH PROC
;code
ret
NumberH ENDP
;----------------------
END main
********************************
Assembling: greater-than1.asm
greater-than1.asm(56) : error A2005: symbol redefinition : main
greater-than1.asm(59) : fatal error A1010: unmatched block nesting : main
take the first section out :bg
bad stuff.....
END NumberH
EXIT
END main
remove that part
good stuff.....
;----------------------
main PROC
;code
exit
main ENDP
;----------------------
NumberH PROC
;code
ret
NumberH ENDP
;----------------------
END main
I apologize for the very 'un thought out' question earlier.
my only issues is not being able to access the variables in the NumberH PROC.
This has to do with main I am sure. Can I just use jmp to get past this the easy way?
***********************code***************************
TITLE GreaterThan
INCLUDE IRVINE32.inc
.data
X BYTE ?
Y BYTE ?
Z BYTE ?
mes1 BYTE "Enter X: ",0
mes2 BYTE "Enter Y: ",0
mes3 byte " is > than ",0
mes4 byte " is < than ",0
mes5 byte " is = to ",0
.code
main PROC
; mov al, 0
mov edx, offset mes1
call writestring
call crlf
call readint
mov edx,offset mes2
call writestring
call crlf
call readint
call NumberH
call DumpRegs
exit
main ENDP
NumberH PROC
mov eax,X
.if eax>Y
mov edx, offset mes3
.elseif eax<Y
mov edx, offset mes4
.else
mov edx, offset mes5
.endif
call writedec
call writestring
mov eax,Y
call writedec
call crlf
ret
NumberH ENDP
END main
ok
you have defined X, Y, and Z as BYTE's
then, you try to MOV them into and compare them with dword registers
the best fix is to make them DWORD's instead of BYTE's
X dd ?
Y dd ?
Z dd ?
Looking better but she still does not want to actually make the comparison?
************code********************
TITLE GreaterThan
INCLUDE IRVINE32.inc
.data
X dword ?
Y dword ?
Z dword ?
mes1 BYTE "Enter X: ",0
mes2 BYTE "Enter Y: ",0
mes3 byte " is > than ",0
mes4 byte " is < than ",0
mes5 byte " is = to ",0
.code
main PROC
; mov al, 0
mov edx, offset mes1
call writestring
call crlf
call readint
mov edx,offset mes2
call writestring
call crlf
call readint
call NumberH
call DumpRegs
exit
main ENDP
NumberH PROC
mov eax,X
.if eax>=Y
mov edx, offset mes3
.elseif eax<=Y
mov edx, offset mes4
.else
mov edx, offset mes5
.endif
call writedec
call writestring
mov eax,Y
call writedec
call crlf
ret
NumberH ENDP
END main
:bg
after ReadInt, don't you want to store the user-entered values ?
mov edx, offset mes1
call WriteString
call CrLf
call ReadInt
mov X,eax ;<----
mov edx,offset mes2
call WriteString
call CrLf
call ReadInt
mov Y,eax ;<----
also, i think this means "equal or greater than"
.if eax>=Y
you probably just want "greater than"
.if eax>Y
.elseif eax<=Y
and for that one, "less than"
.elseif eax<Y