Vous êtes sur la page 1sur 3

CSCI06 Midterms Laboratory Exercises BRANCHING STATEMENTS EXERCISES

Midterms Laboratory Exer1: LOOPING SAMPLE 1 (PUSH AND POP)


.model .code main proc mov ah, 02 mov bl, 01 ;set initial count mov bh, 06 ;set initial count limit push bx ;preserve value of bx initial: mov dl, 31h ;for number 1 start: int 21h ;display value of dl inc bl ;increase value of bl by 1 inc dl ;increase value of dl by 1 cmp bl,bh ;compare bl and bh jne start ;if not equal, go to start pop bx push dx ;restore value of bx ;preserve value of dx value new line to dl a new line value carriage return to dl carriage return

mov dl,10 ;set int 21h ;print mov dl, 13 ;set int 21h ;print

sub bh, 1 ;increase value of bh by 1 pop dx ;restore value of dx push bx ;restore value of bx cmp bh,1 ;compare value of bh je exit ;if bh is equal to the character 7, end program jmp initial ;else, go to initial exit: int 20h main endp end

Midterms Laboratory Exer2: LOOPING SAMPLE 2 (PUSH AND POP)


.model .code main proc mov ah, 02 mov bl, 01 ;set initial count mov bh, 02 ;set initial count limit push bx ;preserve value of bx initial: mov dl, 31h ;for number 1 start: int 21h ;display value of dl inc bl ;increase value of bl by 1 inc dl ;increase value of dl by 1 cmp bl,bh ;compare bl and bh jne start ;if not equal, go to start pop bx push dx ;restore value of bx ;preserve value of dx

mov dl,10 ;set value new line to dl

int 21h ;print a new line mov dl, 13 ;set value carriage return to dl int 21h ;print carriage return add bh, 1 ;increase value of bh by 1 pop dx ;restore value of dx push bx ;restore value of bx cmp bh,07 ;compare value of bh je exit ;if bh is equal to the character 7, end program jmp initial ;else, go to initial exit: int 20h main endp end

Midterms Laboratory Exer3: LOOPING SAMPLE 3 (PUSH AND POP)


.model .code main proc

mov ah, 02 mov dl, 31h ;for number 1 mov bl, 01 ;set initial count mov bh, 02 ;set initial count limit push bx ;preserve value of bx start: int 21h ;display value of dl inc bl ;increase value of bl by 1 cmp bl,bh ;compare bl and bh jne start ;if not equal, go to start pop bx push dx ;restore value of bx ;preserve value of dx value new line to dl a new line value carriage return to dl carriage return

mov dl,10 ;set int 21h ;print mov dl, 13 ;set int 21h ;print

add bh, 1 ;increase value of bh by 1 pop dx ;restore value of dx inc dl ;increase value of dl by 1 push bx ;restore value of bx cmp dl,36h ;compare value of dl je exit ;if dl is equal to the character 6, end program jmp start ;else, go to start exit: int 20h main endp end

Midterms Laboratory Exer4: LOOPING SAMPLE 4 (PUSH AND POP)


.model .code main proc mov ah, 02 mov dl, 35h ;for number 5 mov bl, 01 ;set initial count mov bh, 06 ;set initial count limit push bx ;preserve value of bx start: int 21h inc bl ;display value of dl ;increase value of bl by 1

cmp bl,bh ;compare bl and bh jne start ;if not equal, go to start pop bx push dx ;restore value of bx ;preserve value of dx value new line to dl a new line value carriage return to dl carriage return

mov dl,10 ;set int 21h ;print mov dl, 13 ;set int 21h ;print

sub bh, 1 ;decrease value of bh by 1 pop dx ;restore value of dx dec dl ;decrease value of dl by 1 push bx ;restore value of bx cmp dl,30h ;compare value of dl je exit ;if dl is equal to the character 0, end program jmp start ;else, go to start exit: int 20h main endp end

Midterms Laboratory Exer5: DIAGONAL LETTERS


.model .code main proc

mov ah, 02 mov dl, 61h start: sub dl,20h int 21h push dx mov dl, 0AH int 21h pop dx add dl, 20h inc dl cmp dl, 79H jne start int 20h main endp end

Vous aimerez peut-être aussi