Assembly Programs

Embed Size (px)

DESCRIPTION

a

Citation preview

PROGRAM 1: Prints 0 on the first line, then 1 on the seconda 100mov AH, 2mov DX, 30 ;30 is ASCII for '0'int 21 ;prints character stored in DL if AH=02mov DX, A ;A is ASCII for newlineint 21mov DX, 31 ;31 is ASCII for newlineint 21int 20 ;terminates programrcx100n test.comwqPROGRAM 2: Jump-if-equal demomov AH,2jmp address1mov dx, 30 ;address2int 21int 20mov BX, 2 ;address1cmp BX, 2 ;since BX=2, the ZF flag now equals 1je address2 ;jumps to address1 since ZF=1Note that "cmp number, register" is not valid syntax. If we replace je with jl, the jump will only happen if BX < 2PROGRAM 3: Prints 1 through 9 on different lines, using a loopmov AH, 2mov BX, 30inc BX ;address1mov DX, BXint 21mov DX, aint 21cmp BX, 39jl address1int 20PROGRAM 4: Clears the screenThis program uses int 10, which sets cursor position to (DL, DH) if AH=02, or copies it to (DL, DH) if AH=03. AH=0A writes character AL at current cursor position, but does not move cursor. Note that the AH=03 command resets AX to 00mov AH, 03 ;Makes DX store cursor positionint 10 ;and AL=0startOfLoop:cmp DX, 00 ;Run the loop while cursor is not in topleftje endOfLoop ; cornermov AH, 0A ;Writes character stored in AL to cursor posint 10 ; which is the null characterdec DX ;Moves cursor one backmov AH, 02int 10jmp startOfLoopendOfLoop:mov AH, 0A ;Writes character in topleft corner to nullint 10int 20