Professional Documents
Culture Documents
IT2104
Laboratory Exercise
Procedural and Loop Instructions
Objectives:
Instruction: Analyze the given Emu8086 assembly codes and answer the following questions.
Note: You can execute the program if you have the Emu8086 Emulator installed on your computer.
• The loop instruction in Line 10 is used to repeat the block of code labeled as next: a certain number of
times specified by the count in the cx register. In this case, it repeats the addition of elements from the
vector array to the al register.
3. Which line (number) indicates the total number of vector elements involved in the process?
• Line 49 (vector db 5,4,5,2,1) indicates the total number of vector elements involved in the process.
There are 5 elements in the vector array.
• Lines 39-40 are preparing for the output of the result. They are calling a procedure print_al to print the
value stored in al which is the result of the addition loop.
• Lines 49-50 define an array named vector with the values 5, 4, 5, 2, 1. This array is used in the
addition loop to accumulate the sum in the al register.
• The next: section is a label marking the beginning of a loop. The purpose of this section is to add the
elements of the vector array to the al register in a loop (Lines 8-10) until all elements are processed.
• al is used as an accumulator for the sum of the elements in the vector array.
• bx is used as an index to access elements in the vector array during the addition loop.
8. In the print: section of the program, what does the jz instruction perform?
• The jz instruction in Line 20 checks if the least significant bit of bl is zero. If it is zero, the program
jumps to the zero: label, indicating that the current bit being processed is a 0.
9. In the print_al procedure of the program, what does the jne instruction perform?
• The jne instruction in Line 55 checks if al is not equal to zero. If true, it proceeds to the print_al_r
section, indicating that there are more digits to be processed.
10. In the print_al_r: section of the program, what does the je instruction perform?
• The je instruction in Line 67 checks if the result of the division (ax) is zero. If true, it jumps to pn_done,
indicating that the entire number has been processed.
• The program initializes a vector array, performs a loop to add its elements, stores the result in al,
converts the result to ASCII characters, and prints the ASCII representation. It uses bitwise operations
and conditional jumps to handle the printing process.
2. Based on your perspective, discuss the process within the print_al procedure.
• The print_al procedure is responsible for printing the value stored in al. It checks if al is zero, and if
true, it prints '0'. If al is not zero, it enters a recursive process (print_al_r) to print each digit by dividing
al by 10 and converting the remainder to ASCII. The process involves using the BIOS interrupt 10h for
screen output.