Cs 501 Assignment 1
Solution:
Here's the assembly program to perform the tasks A and B:
Code snippet
; Assuming a simple assembly language with register-based addressing
; Define memory addresses for account balance and salary deduction
ACCOUNT_BALANCE_ADDRESS EQU 114
SALARY_DEDUCTION_ADDRESS EQU 118
; Task A: Load, Add, Load, Subtract
; Load the current account balance into register R1
LDA R1, ACCOUNT_BALANCE_ADDRESS
; Add a bonus of 2000 cents to the account balance
ADD R1, #2000
; Load the salary deduction amount into register R2
LDA R2, SALARY_DEDUCTION_ADDRESS
; Compute the new balance after deduction
SUB R1, R2
; Task B: Show the working mechanism (pseudocode)
; Initial account balance: 3000 cents
; Bonus added: 2000 cents
; Salary deduction: 1500 cents
; New balance after deduction: R1
Use code with caution.
Explanation:
Memory Addresses:
ACCOUNT_BALANCE_ADDRESS and SALARY_DEDUCTION_ADDRESS are defined to hold the memory
addresses of the initial account balance and salary deduction, respectively.
Task A:
LDA R1, ACCOUNT_BALANCE_ADDRESS: Loads the value at the memory address
ACCOUNT_BALANCE_ADDRESS into register R1.
ADD R1, #2000: Adds 2000 (representing $20) to the value in register R1.
LDA R2, SALARY_DEDUCTION_ADDRESS: Loads the value at the memory address
SALARY_DEDUCTION_ADDRESS into register R2.
SUB R1, R2: Subtracts the value in register R2 from the value in register R1, storing the result in R1.
Task B:
The comments in Task B provide a human-readable explanation of the calculations performed.
The final value in register R1 represents the new balance after the bonus and deduction.
Note:
The specific assembly language instructions and syntax may vary depending on the processor and
assembler being used.
The memory addresses and values used in this example are simplified for illustrative purposes. In a real-
world application, the actual memory addresses and values would be determined by the specific system
and data structures.
The pseudocode in Task B provides a clear explanation of the calculations, but it's not directly
executable assembly code. It's a way to visualize the steps involved in the computation.
By following these steps and understanding the assembly instructions, you can implement the
accounting application's logic in assembly language.