0% found this document useful (0 votes)
4 views22 pages

Unit 4

The document is a question bank for the subject 'Microprocessor' at Sanjay Ghodawat Institute, covering various assembly language programming tasks. It includes examples of adding, subtracting, multiplying, and counting operations on both 8-bit and 16-bit numbers, as well as procedures for handling BCD numbers. The content is structured into chapters with specific programming exercises, each detailing the assembly code and comments explaining the functionality.

Uploaded by

alonepiece24
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)
4 views22 pages

Unit 4

The document is a question bank for the subject 'Microprocessor' at Sanjay Ghodawat Institute, covering various assembly language programming tasks. It includes examples of adding, subtracting, multiplying, and counting operations on both 8-bit and 16-bit numbers, as well as procedures for handling BCD numbers. The content is structured into chapters with specific programming exercises, each detailing the assembly code and comments explaining the functionality.

Uploaded by

alonepiece24
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/ 22

Institute Code & Name: SANJAY GHODAWAT INSTITUTE,

ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)

(2 Marks)

1. Write an ALP to add / subtract two 8 bit numbers


.model small ; Define the memory model
.stack 100h ; Define stack size
i)ADD:
.data ; Data segment
num1 db 5 ; First 8-bit number (num1 = 5)
num2 db 3 ; Second 8-bit number (num2 = 3)
result db 0 ; Variable to store the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Add num1 and num2


mov al, num1 ; Load num1 into AL register
add al, num2 ; Add num2 to AL (AL = num1 + num2)
mov result, al ; Store the result in the result variable

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)

end main ; End of program

ii)SUB:
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


num1 db 8 ; First 8-bit number (num1 = 8)
num2 db 3 ; Second 8-bit number (num2 = 3)
result db 0 ; Variable to store the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Subtract num2 from num1


mov al, num1 ; Load num1 into AL register
sub al, num2 ; Subtract num2 from AL (AL = num1 - num2)
mov result, al ; Store the result in the result variable

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


2. Write an ALP to Add / subtract two 16 bit numbers
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


i)ADD:
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


num1 dw 1234h ; First 16-bit number (num1 = 1234h)
num2 dw 5678h ; Second 16-bit number (num2 = 5678h)
result dw 0 ; Variable to store the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Add num1 and num2


mov ax, num1 ; Load num1 into AX register (AX = num1)
add ax, num2 ; Add num2 to AX (AX = num1 + num2)
mov result, ax ; Store the result in the result variable

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program

ii)SUB:
.model small ; Define the memory model
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


.stack 100h ; Define stack size

.data ; Data segment


num1 dw 5678h ; First 16-bit number (num1 = 5678h)
num2 dw 1234h ; Second 16-bit number (num2 = 1234h)
result dw 0 ; Variable to store the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Subtract num2 from num1


mov ax, num1 ; Load num1 into AX register (AX = num1)
sub ax, num2 ; Subtract num2 from AX (AX = num1 - num2)
mov result, ax ; Store the result in the result variable
; End the program
mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


(4 Marks)

1. Write an ALP to multiply two 16 bit signed /unsigned numbers.


i) unsigned
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


num1 dw 1234h ; First 16-bit unsigned number (num1 = 1234h)
num2 dw 5678h ; Second 16-bit unsigned number (num2 = 5678h)
result dw 0 ; Variable to store the lower 16 bits of the result
highResult dw 0 ; Variable to store the higher 16 bits of the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Multiply num1 and num2 (unsigned)


mov ax, num1 ; Load num1 into AX register
mov bx, num2 ; Load num2 into BX register
mul bx ; AX = AX * BX (Unsigned multiplication)
; The result is stored in DX:AX (32-bit result)
mov result, ax ; Store the lower 16 bits of the result in result
mov highResult, dx ; Store the higher 16 bits of the result in highResult

; End the program


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program

ii) signed:
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


num1 dw -1234h ; First 16-bit signed number (num1 = -1234h)
num2 dw 5678h ; Second 16-bit signed number (num2 = 5678h)
result dw 0 ; Variable to store the lower 16 bits of the result
highResult dw 0 ; Variable to store the higher 16 bits of the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Multiply num1 and num2 (signed)


mov ax, num1 ; Load num1 into AX register
mov bx, num2 ; Load num2 into BX register
imul bx ; AX = AX * BX (Signed multiplication)
; The result is stored in DX:AX (32-bit result)
mov result, ax ; Store the lower 16 bits of the result in result
mov highResult, dx ; Store the higher 16 bits of the result in highResult
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


; End the program
mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


2. Write an ALP to count odd numbers in the array of 10 numbers
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


array db 5, 12, 7, 8, 15, 20, 35, 44, 99, 23 ; Array of 10 numbers
count db 0 ; Variable to store the count of odd numbers

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Initialize register for counting odd numbers


mov cx, 10 ; Set loop counter to 10 (for 10 numbers)
lea si, array ; Load the address of array into SI
mov bl, 0 ; Initialize odd number count to 0

check_odd:
mov al, [si] ; Load the current element of the array into AL
and al, 01h ; AND AL with 01h to check if the number is odd (LSB = 1)
jz next_number ; If result is 0 (even), jump to next number
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


inc bl ; If odd, increment count (bl will hold the count)

next_number:
inc si ; Move to the next number in the array
loop check_odd ; Loop until all 10 numbers are checked

; Store the result (count of odd numbers)


mov count, bl ; Store the final count in 'count'

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


3. Write an ALP to find largest number in the array
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


array db 5, 12, 7, 8, 15, 20, 35, 44, 99, 23 ; Array of 10 numbers
largest db 0 ; Variable to store the largest number

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


; Initialize the largest number as the first element of the array
lea si, array ; Load the address of the array into SI register
mov al, [si] ; Load the first number into AL register
mov largest, al ; Assume the first element is the largest

; Loop to find the largest number


mov cx, 9 ; We have 9 more elements to check
inc si ; Move to the next element in the array

find_largest:
mov al, [si] ; Load the current array element into AL
cmp al, largest ; Compare it with the current largest number
jbe next_element ; If AL <= largest, jump to next element
mov largest, al ; Update largest if a larger number is found

next_element:
inc si ; Move to the next element in the array
loop find_largest ; Repeat the loop until all elements are checked

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


4. Write an ALP to count number of ‘0’ in 8 bit number.
.model small ; Define the memory model
.stack 100h ; Define stack size
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)

.data ; Data segment


num db 0FCh ; 8-bit number (example: num = 0FCh)
zero_count db 0 ; Variable to store the count of '0' bits

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Initialize zero_count to 0
mov zero_count, 0 ; Reset zero_count to 0

; Load the 8-bit number into AL register


mov al, num ; AL = num

; Loop through each of the 8 bits of the number


mov cl, 8 ; Loop counter for 8 bits

count_zeros:
; Test the LSB (Least Significant Bit) of AL
test al, 01h ; AL & 01h - checks if the LSB is 0
jnz not_zero ; If LSB is 1 (not zero), jump to not_zero

; If LSB is 0, increment the zero_count


inc zero_count
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


not_zero:
shr al, 1 ; Right shift AL by 1 to examine the next bit
loop count_zeros ; Loop until all 8 bits are checked

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


5. Write an ALP to subtract two BCD number using procedure.
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


num1 db 25h ; First BCD number (25h = 25 in decimal)
num2 db 17h ; Second BCD number (17h = 17 in decimal)
result db 0 ; Variable to store the result

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Call the procedure to subtract two BCD numbers


lea si, num1 ; Load address of num1
lea di, num2 ; Load address of num2
lea dx, result ; Load address of result
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


call sub_bcd ; Call the BCD subtraction procedure

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

; Procedure to subtract two BCD numbers


sub_bcd proc
mov al, [si] ; Load the first BCD number into AL
mov bl, [di] ; Load the second BCD number into BL

; Perform BCD subtraction (AL - BL)


sub al, bl ; AL = AL - BL
jnc no_borrow ; Jump if no borrow (no carry in subtraction)

; Handle borrow (correct the result to be valid BCD)


add al, 0F0h ; Add 0F0h (adjust BCD result when borrow occurs)

; Set the carry flag to indicate borrow in case of BCD subtraction


mov carry_flag, 1 ; Store 1 to carry_flag to indicate borrow

no_borrow:
mov [dx], al ; Store the result in the result variable
ret
sub_bcd endp

end main ; End of program


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


6. Write an ALP to concatenate two strings
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


string1 db 'Hello', 0 ; First string (null-terminated)
string2 db ' World', 0 ; Second string (null-terminated)
result db 50 dup('$') ; Reserve space for the result string (max length 50 characters)

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Load the address of string1 into SI and string2 into DI


lea si, string1 ; Load address of string1 into SI
lea di, result ; Load address of result into DI

; Copy the first string (string1) into the result


copy_string1:
mov al, [si] ; Load byte from string1 into AL
mov [di], al ; Store byte from AL to result
inc si ; Move to next byte of string1
inc di ; Move to next byte of result
cmp al, 0 ; Check if we've reached the null terminator
je copy_string2 ; Jump to copy string2 if null terminator is found
jmp copy_string1 ; Otherwise, continue copying string1
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)

copy_string2:
lea si, string2 ; Load address of string2 into SI
copy_string2_loop:
mov al, [si] ; Load byte from string2 into AL
mov [di], al ; Store byte from AL to result
inc si ; Move to next byte of string2
inc di ; Move to next byte of result
cmp al, 0 ; Check if we've reached the null terminator
je end_program ; Jump to program end if null terminator is found
jmp copy_string2_loop

end_program:
; End the program
mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


7. Write an ALP to perform block transfer operation of 10 numbers
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


source db 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ; Source block of 10 numbers
destination db 10 dup(0) ; Destination block (initialized to 0)

.code ; Code segment


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Set up source and destination addresses


lea si, source ; Load the address of source array into SI
lea di, destination ; Load the address of destination array into DI

; Transfer 10 bytes (block of 10 numbers)


mov cx, 10 ; Set the counter to 10 (for 10 numbers)
block_transfer:
mov al, [si] ; Load byte from source (SI) into AL
mov [di], al ; Store byte from AL to destination (DI)
inc si ; Increment SI to point to the next source byte
inc di ; Increment DI to point to the next destination byte
loop block_transfer ; Loop until 10 bytes are transferred

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


8. Write an ALP to find length of string
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


string db 'Hello World!', 0 ; Null-terminated string

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Load the address of the string into SI


lea si, string ; Load address of string into SI

; Initialize the counter for length


mov cx, 0 ; Set CX to 0 (will store the length)

find_length:
mov al, [si] ; Load byte from string into AL
cmp al, 0 ; Compare AL with 0 (null terminator)
je done ; If AL is 0 (end of string), jump to done
inc si ; Move to the next character in the string
inc cx ; Increment the length counter
jmp find_length ; Repeat the process for the next character

done:
; Now CX contains the length of the string
; The length of the string is stored in CX register

; Terminate the program


mov ah, 4Ch ; DOS interrupt to exit program
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


int 21h ; Call interrupt to terminate the program

end main ; End of program


9. Write an ALP to check a given number is positive or negative
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


msg_positive db 'The number is positive.$' ; Message for positive number
msg_negative db 'The number is negative.$' ; Message for negative number

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Load the number to be checked into AX


mov ax, 0FFFFh ; Example negative number (replace with any 16-bit value)

; Check the sign of the number (using the MSB)


; The MSB is in bit 15, so we check if the number is negative (if the MSB is 1)
; For negative numbers, the most significant bit (MSB) is 1, i.e., 0x8000 for signed
numbers.

; If the MSB is 1, the number is negative


; We can check this using the `js` (Jump if Sign) instruction.
js negative_number ; Jump to negative_number if the sign flag (SF) is set
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)

; If the number is positive, display the positive message


lea dx, msg_positive ; Load the address of the positive message
mov ah, 09h ; DOS function to display string
int 21h ; Call DOS interrupt to display the string
jmp end_program ; Jump to program end

negative_number:
; If the number is negative, display the negative message
lea dx, msg_negative ; Load the address of the negative message
mov ah, 09h ; DOS function to display string
int 21h ; Call DOS interrupt to display the string

end_program:
; End the program
mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program


10. Write an ALP to count ODD and/or EVEN numbers in array .
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


array db 5, 2, 7, 10, 15, 8, 9, 4, 3, 6 ; Array of 10 numbers
odd_count db 0 ; Counter for odd numbers
even_count db 0 ; Counter for even numbers
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


msg_odd db 'Odd count: $' ; Message to display odd count
msg_even db 'Even count: $' ; Message to display even count

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Load the address of the array into SI


lea si, array ; Load address of the array into SI

; Initialize counters to 0
mov byte ptr odd_count, 0
mov byte ptr even_count, 0

; Loop through the array (assuming the array has 10 numbers)


mov cx, 10 ; Set counter for array size (10 elements)

check_numbers:
mov al, [si] ; Load current array element into AL
and al, 1 ; Perform bitwise AND with 1 to check LSB (odd or even)
jz even_number ; Jump if the number is even (AL is 0)

; Odd number case


inc byte ptr odd_count ; Increment odd count
jmp next_element ; Jump to the next element
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


even_number:
inc byte ptr even_count ; Increment even count

next_element:
inc si ; Move to the next element in the array
loop check_numbers ; Repeat for all array elements

; Display Odd Count


lea dx, msg_odd ; Load the address of the odd count message
mov ah, 09h ; DOS function to display string
int 21h ; Call DOS interrupt to display string
mov al, odd_count ; Load odd count into AL
call PrintNum ; Call PrintNum to display the number

; Display Even Count


lea dx, msg_even ; Load the address of the even count message
mov ah, 09h ; DOS function to display string
int 21h ; Call DOS interrupt to display string
mov al, even_count ; Load even count into AL
call PrintNum ; Call PrintNum to display the number

; End the program


mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

PrintNum proc
; Function to print number in AL
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


add al, '0' ; Convert number to ASCII
mov dl, al ; Move the ASCII number to DL for printing
mov ah, 02h ; DOS function to print a character
int 21h ; Call DOS interrupt to print character
ret
PrintNum endp

end main ; End of program


11. Write an ALP to transfer 10 bytes of data from one memory location to
another, also draw the flow chart of the same
.model small ; Define the memory model
.stack 100h ; Define stack size

.data ; Data segment


source db 10h, 20h, 30h, 40h, 50h, 60h, 70h, 80h, 90h, A0h ; Source array of 10 bytes
destination db 10 dup (?) ; Destination array (empty initially)

.code ; Code segment


main: ; Main program start
mov ax, @data ; Initialize data segment
mov ds, ax

; Set the source and destination addresses


lea si, source ; Load address of source into SI
lea di, destination ; Load address of destination into DI

; Initialize counter for 10 bytes


mov cx, 10 ; Set CX to 10 for transferring 10 bytes

transfer_loop:
mov al, [si] ; Load byte from source (pointed by SI) into AL
mov [di], al ; Store byte from AL into destination (pointed by DI)

inc si ; Increment source index (SI) to point to the next byte


inc di ; Increment destination index (DI) to point to the next byte

loop transfer_loop ; Repeat the process for 10 bytes


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 4 : Assembly Language Programming (CO4) (20 Marks)


; End the program
mov ah, 4Ch ; DOS interrupt to exit program
int 21h ; Call interrupt to terminate the program

end main ; End of program

You might also like