2013-10-10 115 views
0
TITLE Allowance 


INCLUDE irvine32.inc 

.DATA 
welcomeMessage BYTE "Welcome To Allowance Calculator", 0 ; 
inputMessage BYTE "Please Enter Salary", 0 ; 
salary WORD ? 
allowance WORD ? 
total WORD ? 

ten WORD 10 
five WORD 5 
hundred WORD 100 
limit WORD 2D 

great BYTE "I'm in greater" 

.CODE 
main PROC 
    MOV EAX, 0 
    MOV EBX, 0 
    MOV ECX, 0 
    MOV EDX, 0 
    Sub limit, 1D 

    Call DumpRegs 

    MOV EDX, offset welcomeMessage 
    Call WriteString 

    MOV EDX, offset inputMessage 
    Call WriteString 
    Call ReadDec 
    MOV salary, Ax 

    cmp Ax, 100D 
    Call DumpRegs 
    Call WriteInt 

    JLE lesser 
    JG greater 

    greater: 
    MOV EDX, offset great 
    Call WriteString 
    MOV EAX, 0 
    MOV Ax, salary 
    MUL ten 
    DIV hundred 

    MOV allowance, Ax 
    Call WriteInt 
    JMP end1 

    lesser: 
     MOV EAX, 0 
     MOV Ax, salary 
     MUL five 
     DIV hundred 

     MOV allowance, Ax 
     Call WriteInt 
     JMP end1 

    end1: 
     exit 
main ENDP 

END主要CMP聲明不給正確的結果

當我使用CMP命令比較它只是帶我去JGE ..不管是什麼值..任何解決這個好嗎?

我也嘗試過使用JE並給出了相同的意見,但即使如此,它也把我帶到更大的標籤。

+2

DumpRegs和/或WriteInt很可能重挫的標誌。 –

回答

3

cmp指令修改標誌和跳轉指令決定標誌狀態。這些標誌也許這些call的(正確剛剛WriteInt)修改:

Cmp Ax, 100D 
Call DumpRegs 
Call WriteInt 
JLE lesser 
JG greater 

jlejg的行爲將無法預料。你可以調用使用pushf之前存儲的標誌狀態,然後使用popf,像他們恢復回來:

Cmp Ax, 100D 
pushf 
Call DumpRegs 
Call WriteInt 
popf 
JLE lesser 
JG greater