0% found this document useful (0 votes)
19 views13 pages

Computer Organization and Assembly Language (COAL) Lab 9: Ali Naqi (23F-3052)

The document contains assembly language code for various programs, including functions to clear the screen, check for prime numbers, perform bitwise AND operations, and reverse a number. Each program begins with a jump to a start label and includes subroutines for specific tasks. The code is structured with comments and labels for clarity, demonstrating basic computer organization and assembly language principles.

Uploaded by

alinaqi1129
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views13 pages

Computer Organization and Assembly Language (COAL) Lab 9: Ali Naqi (23F-3052)

The document contains assembly language code for various programs, including functions to clear the screen, check for prime numbers, perform bitwise AND operations, and reverse a number. Each program begins with a jump to a start label and includes subroutines for specific tasks. The code is structured with comments and labels for clarity, demonstrating basic computer organization and assembly language principles.

Uploaded by

alinaqi1129
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Computer Organization and Assembly Language (COAL)

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

yes :db ' is a prime number'


l1:dw 18
no :db ' is not a prime number'
l2: dw 22

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

mov di, [bp+10]

mov ax, 0xb800


mov es, ax
mov ax, [bp+4]
mov bx, 10
mov cx, 0

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

mov si, [bp+8]


mov cx, [bp+6]
mov ah, 0x07
nextchar:
mov al, [si]
mov [es:di], ax
add di, 2
add si, 1
loop nextchar

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

yes :db ' is the final reuslt'


len1:dw 20

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

mov di, [bp+10]

mov ax, 0xb800


mov es, ax
mov ax, [bp+4]
mov bx, 10
mov cx, 0

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

mov si, [bp+8]


mov cx, [bp+6]
mov ah, 0x03
nextchar:
mov al, [si]
mov [es:di], ax
add di, 2
add si, 1
loop nextchar

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

before :db 'Before Reversing: '


after :db 'After Reversing: '
len :dw 18

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

mov di, [bp+10]

mov ax, 0xb800


mov es, ax

mov si, [bp+8]


mov cx, [bp+6]
mov ah, 0x07
nextchar:
mov al, [si]
mov [es:di], ax
add di, 2
add si, 1
loop nextchar
mov ax, [bp+4]
mov bx, 10
mov cx, 0

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy