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

Code 501

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)
3 views

Code 501

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/ 4

; Define memory addresses for account balance and fine deduction

.ORG 100

INITIAL_BALANCE: .DW 3000 ; Memory address 114, represents $30.00

FINE_DEDUCTION: .DW 1500 ; Memory address 118, represents $15.00

.ORG 200 ; Start code at address 200

; Task A: Load initial balance and apply bonus

LD R1, INITIAL_BALANCE ; Load account balance (3000 cents) into R1

ADDI R1, R1, 2000 ; Add bonus of 2000 cents ($20.00), R1 = 5000

; Load fine deduction

LD R2, FINE_DEDUCTION ; Load fine amount (1500 cents) into R2

; Task B: Deduct fine from balance

SUB R1, R1, R2 ; Subtract R2 from R1, R1 = 3500 (new balance)

; Store result back (optional, if needed to store in memory)

ST R1, INITIAL_BALANCE ; Store updated balance back to memory

HALT ; End program

‫دوسرا‬

; Task A: Calculate the new account balance after bonus and fine deduction
; Load the initial account balance from memory address 114

MOV AX, [114] ; AX register holds the account balance (3000 cents)

; Add the bonus amount to the account balance

ADD AX, 2000 ; Add 2000 cents ($20.00) to the balance

; Load the fine amount from memory address 118

MOV BX, [118] ; BX register holds the fine amount (1500 cents)

; Deduct the fine from the updated account balance

SUB AX, BX ; Subtract the fine from the updated balance in AX

; Task B: Show the final balance after calculations

; Display the result stored in AX (final balance)

; (Assume a mechanism to display AX value, such as a system call or printing routine)

; This part may vary depending on the system, so here it’s abstractly represented

END_PROGRAM:

HLT ; Stop the program execution

‫تیسرا‬

Section .data

Initial_balance dw 3000 ; Initial account balance in cents

Fine_deduction dw 1500 ; Fine amount in cents

Section .text

Org 0x100 ; Set the origin for DOS .COM files


Start:

; Load initial balance into AX

Mov ax, [initial_balance] ; Load initial balance

; Add bonus of $20.00 (2000 cents)

Add ax, 2000 ; Update AX with the new balance

; Load fine deduction into BX

Mov bx, [fine_deduction] ; Load fine amount

; Subtract fine from AX

Sub ax, bx ; Final balance in AX

; Display the result (print AX)

; Convert AX to ASCII and display it

Call print_number

; Exit program

Mov ah, 0x4C

Int 0x21

Print_number:

; Print AX as a decimal number

Push ax

Mov cx, 0

Next_digit:

Mov dx, 0

Div word [ten]


Add dl, ‘0’

Push dx

Inc cx

Test ax, ax

Jnz next_digit

Print_digits:

Pop dx

Mov ah, 0x02

Int 0x21

Loop print_digits

Pop ax

Ret

Section .data

Ten dw 10

You might also like