0% found this document useful (0 votes)
16 views14 pages

23F 0043 BAI 4A COAL Assignment 1

The document contains a series of assembly language code snippets addressing various programming tasks, including loops, array manipulation, and calculations such as sum and factorial. Each question includes code with comments and outputs, demonstrating different addressing modes and control flow structures. The final output includes the results of the computations performed by the code.

Uploaded by

maaismusakhu
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)
16 views14 pages

23F 0043 BAI 4A COAL Assignment 1

The document contains a series of assembly language code snippets addressing various programming tasks, including loops, array manipulation, and calculations such as sum and factorial. Each question includes code with comments and outputs, demonstrating different addressing modes and control flow structures. The final output includes the results of the computations performed by the code.

Uploaded by

maaismusakhu
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/ 14

COAL ASSIGNMENT

Name: Hafiz Muhammad Huzaifa


Roll# 23F-0043
Section: BAI-4A
Submitted to: Sir Hamza Yousaf

Question 2:
Code:
[org 0x0100]

mov si, 0

mov ax, 0
outerloop:

mov bx, ax
innerloop:

add si, 1

add bx, 2
cmp bx, 8
jle innerloop

add ax, 1
cmp ax, 3
jle outerloop

mov ax, 0x4C00


int 0x21
Output:
Question 3:
Code:
[org 0x0100]

mov ax, [array] ; storing the max value


mov bx, array ; storing the address of the array
mov cx, 0 ; storing the sum of the array
mov dx, 5 ; storing the number of elements in the array

outerloop:
add cx, [bx]
cmp [bx], ax
jg condmax

next:
add bx, 2
sub dx, 1
jnz outerloop

jmp end

condmax:
mov ax, [bx]
jmp next

end:
mov ax, 0x4C00
int 0x21

array: dw 5, 8, 2, 4, 7
Output:

Question 4:
Code:
[org 0x0100]

mov al, [digit1]


add [sum], al
mov al, [digit2]
add [sum], al
mov al, [digit3]
add [sum], al
mov al, [digit4]
add [sum], al
mov al, [digit5]
add [sum], al
mov ax, 0x4C00
int 0x21

digit1: db 2
digit2: db 3
digit3: db 0
digit4: db 4
digit5: db 3
sum: db 0
Output:

In this I use direct addressing mode by directly accessing data from memory
variables digit1, digit2, digit3, digit4, and digit5 and store in memory variable
sum.
Question 5:
Code:
[org 0x0100]
; load 25h into ax
mov ax, 25h

; swap ax and bx
xor ax, bx
xor bx, ax
xor ax, bx
; load content of memory location 0x3321 into cx
mov cx, [0x3321]

; load contents of array in ax using index addressing


mov si, array
mov ax, [si]

add si, 2
add ax, [si]

add si, 2
add ax, [si]

mov ax, 0x4C00


int 0x21

array: dw 2, 5, 9
Output:
Question 6:
Code:
[org 0x0100]

mov ax, 0 ; where sum is stored


mov bx, 0

outerloop:
add ax, [array + bx]
add bx, 2
cmp bx, 24
jne outerloop

mov ax, 0x4C00


int 0x21

array: dw 111, 999, 888, 888, 11, 99, 88, 88, 1, 9, 8, 8


Output:
Question 7:
Code:
[org 0x0100]

mov ax, 5 ; number whose factorial is to be calculated and stored


in ax
mov bx, ax
sub bx, 1

factorial:
cmp bx, 1
jle end

mov cx, ax
mov dx, bx
sub dx, 1

multiply:
add ax, cx
sub dx, 1
jz next
jmp multiply
next:
sub bx, 1
jmp factorial

end:
mov [huzaifa], ax

mov ax, 0x4C00


int 0x21

huzaifa: dw 0
Output:

Question 8:
Code:
[org 0x0100]

mov bx, 0

mov cx, [array + bx]


mov [minimum], cx
mov [maximum], cx

add bx, 2
outerloop:
mov cx, [array + bx]

cmp cx, [minimum]


jl condmin

cmp cx, [maximum]


jg condmax

next:
add bx, 2
cmp bx, 10
jl outerloop

jmp end

condmin:
mov [minimum], cx
jmp next

condmax:
mov [maximum], cx
jmp next

end:
mov ax, 0x4C00
int 0x21

array: dw 6, 4, 2, 7, 8
maximum: dw 0
minimum: dw 0
Output:
Question 9:
Code:
[org 0x0100]

mov si, 0

outerloop:

mov bx, si
add bx, 2

innerloop:
mov cx, [nums + si]
cmp cx, [nums + bx]
jl swap

nextinner:
add bx, 2
cmp bx, 30
jl innerloop

add si, 2
cmp si, 28
jl outerloop

jmp end

swap:
mov cx, [nums + si]
xor cx, [nums + bx]
mov [nums + si], cx

mov cx, [nums + bx]


xor cx, [nums + si]
mov [nums + bx], cx

mov cx, [nums + si]


xor cx, [nums + bx]
mov [nums + si], cx

jmp nextinner

end:
mov ax, 0x4C00
int 0x21

nums: dw 60, 55, -55, 60, -60, 58, -58, -58, 25, 15, 34, 87, 90, 12, 65
Output:

You might also like