0% found this document useful (0 votes)
12 views2 pages

CS501 Solution

b

Uploaded by

princeimups2018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

CS501 Solution

b

Uploaded by

princeimups2018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS501 Assignment 1 :

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)

; 2. Add bonus of 2000 cents (20.00)


add ax, [bonus] ; AX = 5000 (Account Balance + Bonus)

; 3. Load salary deductions into BX register


mov bx, [salary_deductions] ; BX = 1500 (Salary Deductions)

; 4. Subtract deductions from account balance


sub ax, bx ; AX = AX - BX (AX = 3500)

; 5. Store the final balance in memory


mov [new_balance], ax ; Store AX (3500) in new_balance

; Display the result (optional, for checking the result)


; Convert AX (final balance) to string for display
; We will just exit the program after calculation in this example

; Exit program (using DOS interrupt)


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

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.

You might also like