Check of two numbers
A program that checks two given integers. It returns true if one of them equals 30 or if their sum equals 30.
Program source code
title .286C .model small .stack 100h data segment public fmtout db "Result: %s\n\0" data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure push 25 ; Save the value 25 on the stack push 5 ; Save the value 5 on the stack call Calculate ; Call the Calculate procedure (return value in ax) push ax ; 2nd: save the ax register value on the stack lea ax, ds:[fmtout] ; 1st: load the address of the fmtout format string into ax call PrintFormatString ; Call the PrintFormatString procedure add sp, 2 ; Align the stack xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure Calculate proc ; Start of the Calculate procedure push bp ; Save the bp register value on the stack mov bp, sp ; Copy the sp register value into bp pushf ; Save the FLAGS register value on the stack data segment msg_true db "True\0" msg_false db "False\0" data ends cmp word ptr ss:[bp+4], 30 ; Compare the value on the stack [bp+4] with the number 30 jz @True ; If ZF=1, jump to the @True label cmp word ptr ss:[bp+6], 30 ; Compare the value on the stack [bp+6] with the number 30 jz @True ; If ZF=1, jump to the @True label mov ax, word ptr ss:[bp+4] ; Copy the first parameter on the stack at [bp+4] into ax add ax, word ptr ss:[bp+6] ; Add the value of the second parameter at [bp+6] to the ax register cmp ax, 30 ; Compare the value in the ax register with the number 30 jz @True ; If ZF=1, jump to the @True label lea ax, ds:[msg_false] ; Load the address of the msg_false variable into the ax register jmp @Done ; Jump unconditionally to the @Done label @True: lea ax, ds:[msg_true] ; Load the address of the msg_true variable into the ax register @Done: popf ; Pop the flags from the stack into the FLAGS register pop bp ; Pop the value from the stack into bp ret 4 ; Return from the procedure with the stack aligned by 4 bytes Calculate endp ; End of the Calculate procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Result: True
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".