0% found this document useful (0 votes)
32 views

CS501 Assignment Solution

Uploaded by

azka asif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

CS501 Assignment Solution

Uploaded by

azka asif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS501 - Advance Computer Architecture

Assignment Solution:
Student Name: AZKA ASIF
Student ID: BC210202844

section.data

account balance db 3000

address (3000 cents = $30.00)

fine_amount db 1500

address (1500 cents = $15.00)

section .text

global_start

start:

: Part Task A

1. Load the current account balance into a register

mov eax, [account balance] : Move the account balance from memory to
EAX register (3000 cents)

2. Add a bonus of $20.00 (2000 cents) to the account balance


add eax, 2000 balance (5000 cents) ; Add 2000 cents to EAX, EAX now holds
updated

; 3. Load the fine/deduction amount into another register

mov ebx, [fine_amount] register (1500 cents) ; Move the fine amount from memory to EBX

; 4. Compute the new balance after deducting the fine

sub eax, ebx (final balance: 3500 cents) ; Subtract fine amount in EBX from balance in
EAX

Part Task B
Convert final balance In EAX to a string and print (specifics vary by OS; example shown for
Linux)

For simplicity, this program assumes an output mechanism will display the final balance

; Exit the program

mov eax, 1 : Syscall number for exit (on Linux x86)


Int 0x80 ; Call kernel to exit

Explanation of Code
1. Define the Data Section (section.data):
account_balance db 3000: This line stores the initial account balance as 3000 cents (equivalent to
$30.00) In a data section.
fine_amount db 1500: This line stores the fine or deduction amount as 1500 cents (equivalent to
$15.00).

2. Begin Code Execution (in_start section):


* Step 1: mov eax, [account balance]
This command loads the Initial account balance (3000 cents) from memory Into the EAX
register. Now EAX holds the value 3000.

* Step 2: add eax, 2000


Here, we add a bonus of 2000 cents ($20.00) to the balance in EAX. After this addition, EAX
contains the updated balance, which is 3000 + 2000 = 5000 cents ($50.00).

Step 3: mov ebx, [fine amount]


This line load's the fine amount (1500 cents) from memory Into the EBX register. Now EBX
holds the value 1500.

* Step 4: sub eax, ebx


This command subtracts the fine amount in EBX (1500 cents) from the updated balance in EAX
(5000 cents). The result, 5000 -1500 3500 cents, is stored back in EAX, which is now the final
balance of $35.00.

3. Exit the Program:


mov eax, 1 and Int 0x80 This is a system call for program exit in Linux x86 assembly. The mov
eax, 1 sets up the exit system call, and int 0x80 interrupts the program, telling the OS to end the
program.

You might also like