CS501 Solution
CS501 Solution
STUDENT ID :
SOLUTION:
; Assembly program for salary bonus calculation in 16-bit DOS mode (NASM)
section .data
account_balance dw 3000 ; $30.00 (in cents)
salary_deductions dw 1500 ; $15.00 (in cents)
bonus dw 2000 ; $20.00 (in cents)
section .bss
new_balance resw 1 ; Placeholder for new balance
section .text
global _start
_start:
; 1. Load account balance into AX register
mov ax, [account_balance] ; AX = 3000 (Account Balance)
EXPLANATION:
Task A:
1. Loads the Account Balance:
o The account balance (3000 cents) is stored at memory address account_balance and
loaded into the AX register using the instruction mov ax, [account_balance].
2. Adds the Bonus:
o A bonus of 2000 cents (representing $20.00) is stored in the bonus variable. We add this
value to the current account balance using the add ax, [bonus] instruction. This updates
the AX register to the new value 5000 (representing $50.00).
3. Loads the Salary Deductions:
o The salary deduction (1500 cents or $15.00) is loaded into the BX register using mov bx,
[salary_deductions].
4. Computes the New Balance:
o We subtract the deduction amount (BX) from the updated account balance (AX). The
result (3500 cents or $35.00) is stored back in the AX register.
Task B:
After the deductions, the final balance of 3500 cents ($35.00) is stored in the new_balance memory
location. The program then ends, using the DOS interrupt int 21h to terminate.