Computer Organization and Assembly Language (COAL) Lab 9: Ali Naqi (23F-3052)
Computer Organization and Assembly Language (COAL) Lab 9: Ali Naqi (23F-3052)
Lab 9
Ali Naqi (23F-3052)
Question 1:
Code:
[org 0x0100]
jmp start
clrscr:
push di
push es
push ax
mov di,0
mov ax,0xb800
mov es,ax
mov ax,0x0720
mov di,0
mov cx,2000
cld
rep stosw
pop ax
pop es
pop di
ret
pattren:
push bp
mov bp,sp
push es
push ax
push cx
push si
push di
mov ax, 0xb800
mov es, ax
mov di,1500
mov dx,[bp+4]
mov si,-1
mov ax, 0x072a
cld
call clrscr
outerLoop:
add si,2
mov cx,si
rep stosw
add di,160
shl si,1
sub di,si
shr si,1
dec dx
jnz outerLoop
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 2
start:
mov ax,4
push ax
call pattren
mov ax,0x4c00
int 0x21
Output:
Question 2:
Code:
[org 0x0100]
jmp start
clrscr:
push di
push es
push ax
mov di,0
mov ax,0xb800
mov es,ax
mov ax,0x0720
mov di,0
mov cx,2000
cld
rep stosw
pop ax
pop es
pop di
ret
printstr:
push bp
mov bp,sp
push es
push ax
push cx
push si
push di
call clrscr
nextdigit:
mov dx, 0
div bx
add dl, 0x30
push dx
inc cx
cmp ax, 0
jnz nextdigit
nextpos:
pop dx
mov dh, 0x02
mov [es:di], dx
add di, 2
loop nextpos
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
checkPrime:
push bp
mov bp,sp
push ax
push cx
push bx
push si
mov ax,[bp+4]
mov cx,ax
sub cx,2
mov bx,2
outerLoop:
mov dx,0
div bx
cmp dx,0
je false
mov ax,[bp+4]
inc bx
dec cx
jnz outerLoop
jmp true
false:
mov ax,160
push ax
mov ax,no
push ax
mov ax,[l2]
push ax
mov ax,[bp+4]
push ax
call printstr
jmp exit
true:
mov ax,160
push ax
mov ax,yes
push ax
mov ax,[l1]
push ax
mov ax,[bp+4]
push ax
call printstr
exit:
pop si
pop bx
pop cx
pop ax
pop bp
ret 2
start:
mov ax,7
push ax
call checkPrime
mov ax,0x4c00
int 0x21
Output:
Question 3:
Code:
[org 0x0100]
jmp start
clrscr:
push di
push es
push ax
mov di,0
mov ax,0xb800
mov es,ax
mov ax,0x0720
mov di,0
mov cx,2000
cld
rep stosw
pop ax
pop es
pop di
ret
printstr:
push bp
mov bp,sp
push es
push ax
push cx
push si
push di
call clrscr
nextdigit:
mov dx, 0
div bx
add dl, 0x30
push dx
inc cx
cmp ax, 0
jnz nextdigit
nextpos:
pop dx
mov dh, 0x02
mov [es:di], dx
add di, 2
loop nextpos
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
BitWiseAnd:
push bp
mov bp,sp
push ax
push cx
push bx
push si
mov al,[bp+6]
mov bl,[bp+4]
and al,bl
mov cl,al
mov ax,160
push ax
mov ax,yes
push ax
mov ax,[len1]
push ax
mov ah,0
mov al,cl
push ax
call printstr
pop si
pop bx
pop cx
pop ax
pop bp
ret 4
start:
mov ax,3
push ax
mov ax,5
push ax
call BitWiseAnd
mov ax,0x4c00
int 0x21
Output:
Question 4:
Code:
[org 0x0100]
jmp start
clrscr:
push di
push es
push ax
mov di,0
mov ax,0xb800
mov es,ax
mov ax,0x0720
mov di,0
mov cx,2000
cld
rep stosw
pop ax
pop es
pop di
ret
printstr:
push bp
mov bp,sp
push es
push ax
push cx
push si
push di
nextdigit:
mov dx, 0
div bx
add dl, 0x30
push dx
inc cx
cmp ax, 0
jnz nextdigit
nextpos:
pop dx
mov dh, 0x02
mov [es:di], dx
add di, 2
loop nextpos
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
reverse:
push bp
mov bp,sp
push ax
push cx
push bx
push si
call clrscr
mov cx,8
mov ax,160
push ax
mov ax,before
push ax
mov ax,[len]
push ax
mov ax,[bp+4]
push ax
call printstr
l1:
shr ax,1
jc push1
mov bx,0
push bx
jmp next
push1
mov bx,1
push bx
next:
loop l1
mov cx,8
mov ax,0
l2:
pop bx
cmp bx,1
je insert1
clc
rcr al,1
jmp next1
insert1:
stc
rcr al,1
next1:
loop l2
mov bx,ax
mov ax,320
push ax
mov ax,after
push ax
mov ax,[len]
push ax
mov ax,bx
push ax
call printstr
pop si
pop bx
pop cx
pop ax
pop bp
ret 2
start:
mov ax,209
push ax
call reverse
mov ax,0x4c00
int 0x21
Output: