Assignment Computer Architecture
Assignment Computer Architecture
Programs
1. To calculate the greatest common divisor (GCD) of two numbers using the Euclidean algorithm.
2. To compute the sum of all odd numbers within a given range.
3. To divide a number by 7 and print the result as an ASCII string.
Program 1: GCD of Two Numbers
1.1 Objective:
To calculate the greatest common divisor (GCD) of two numbers using the Euclidean algorithm.
1.2 Explanation:
This program calculates the GCD of two numbers using the Euclidean algorithm. The algorithm repeatedly divides the larger
number by the smaller one, replacing the larger number with the remainder. This process continues until the remainder becomes
zero, at which point the smaller number is the GCD. The program is implemented in x86 assembly and uses basic arithmetic
operations such as division and comparison. Registers are used to store intermediate results, and the final GCD is stored in the
`result` variable. To make the output user-friendly, the result is converted into an ASCII string and printed. This program also
CODE OUTPUT
Program 2: Sum of Odd Numbers in a Range
2.1 Objective:
2.2 Explanation:
This program calculates the sum of odd numbers within a specified range. The range is defined using the `start` and
`end` variables. The program iterates through all numbers in the range, checking whether each number is odd using a bitwise AND
operation (`test al, 1`). Odd numbers are added to an accumulator (`ecx`) that stores the running total. After processing all numbers,
the total sum is stored in the `sum` variable, converted to ASCII, and printed. This ensures accurate and user-friendly output. The
program is written in x86 assembly and adheres to proper coding standards. The student ID is prominently included in the comments
CODE OUTPUT
Program 3: Division of a Number by 7
3.1 Objective:
3.2 Explanation:
This program divides a given 16-bit number (student number) by 7 and prints the quotient to the console. The program uses the `div`
instruction to perform the division operation, storing the quotient in the `eax` register and the remainder in
`edx’. A custom subroutine converts the quotient into an ASCII string. The result is printed along with a descriptive message. This
implementation demonstrates an efficient approach to division and ASCII conversion in x86 assembly. Proper coding standards,
such as meaningful comments and organized code structure, are followed. The student ID is included in the comments to ensure
identification. For the input 70, the program calculates a quotient of 00010, which is printed to the console.
CODE OUTPUT