GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, December 21, 2010

Assembly CMP and JZ

JZ is a jump command. It tell the program to jump if zero. Zero means that the two value in CMP in quantities is equal (if it subtracted, the result is zero).

start:
    MOV AH,08    ; Function to read keyboard input
    INT 21h      ; and save it to AL
    CMP AL,65    ; Compare what saved in AL by 65 ("A")
    JZ output    ; If result of CMP is "ZERO" (same as "A"),  
                 ; jump to output and skip middle.

middle:
    MOV AH,02    ; Function to output char
    MOV DL,"N"   ; Char to output
    INT 21h

output:
    MOV AH,02    ; Function to output char
    MOV DL,"M"   ; Char to output
    INT 21h

exit:
    MOV AH,4Ch   ; Function to exit
    MOV AL,00     ; return 0
    INT 21h

If you type "A", then it will skip middle label
output> N

But if you type other than "A", then the output is:
output> NM
Share/Bookmark

No comments:

Post a Comment