Flag Electric Current> assembly language code...
question mark

For the following mathematical expressions write an assembly language code:

(a) For Reg-Reg architecture (10)

(b) For Reg-Mem architecture (10)

U = A + B + D

V = C + D

W= B << 3

X = 7B + B + C+ D

Y = X + V

Aadee Mughal , 13 Years ago
Grade
anser 1 Answers
Askiitians Tutor Team

To tackle the task of writing assembly language code for the given mathematical expressions, we need to consider the two different architectures: Register-Register (Reg-Reg) and Register-Memory (Reg-Mem). Each architecture has its own way of handling data and instructions, which influences how we write the assembly code. Let's break this down step by step.

Assembly Code for Reg-Reg Architecture

In a Register-Register architecture, all operations are performed between registers. This means we need to load values into registers before performing any calculations. Here’s how we can represent the expressions:

  • U = A + B + D
  • V = C + D
  • W = B << 3
  • X = 7B + B + C + D
  • Y = X + V

Here’s the assembly code for the Reg-Reg architecture:

; Assume A, B, C, D are stored in memory locations
; Load values into registers
LOAD R1, A      ; Load A into R1
LOAD R2, B      ; Load B into R2
LOAD R3, C      ; Load C into R3
LOAD R4, D      ; Load D into R4

; Calculate U = A + B + D
ADD R1, R2      ; R1 = A + B
ADD R1, R4      ; R1 = U = A + B + D

; Calculate V = C + D
ADD R3, R4      ; R3 = V = C + D

; Calculate W = B << 3
SHL R2, 3       ; R2 = W = B << 3

; Calculate X = 7B + B + C + D
MUL R2, 7       ; R2 = 7B
ADD R2, R2      ; R2 = 8B
ADD R2, R3      ; R2 = 8B + C
ADD R2, R4      ; R2 = X = 8B + C + D

; Calculate Y = X + V
ADD R2, R3      ; R2 = Y = X + V

Assembly Code for Reg-Mem Architecture

In a Register-Memory architecture, operations can directly involve memory locations. This allows for a slightly different approach since we can perform operations without needing to load everything into registers first. Here’s how the assembly code would look:

  • U = A + B + D
  • V = C + D
  • W = B << 3
  • X = 7B + B + C + D
  • Y = X + V

Here’s the assembly code for the Reg-Mem architecture:

; Assume A, B, C, D are stored in memory locations
; Calculate U = A + B + D
LOAD R1, A      ; Load A into R1
ADD R1, B       ; R1 = A + B
ADD R1, D       ; R1 = U = A + B + D
STORE R1, U     ; Store U back to memory

; Calculate V = C + D
LOAD R2, C      ; Load C into R2
ADD R2, D       ; R2 = V = C + D
STORE R2, V     ; Store V back to memory

; Calculate W = B << 3
LOAD R3, B      ; Load B into R3
SHL R3, 3       ; R3 = W = B << 3
STORE R3, W     ; Store W back to memory

; Calculate X = 7B + B + C + D
LOAD R4, B      ; Load B into R4
MUL R4, 7       ; R4 = 7B
ADD R4, B       ; R4 = 8B
LOAD R5, C      ; Load C into R5
ADD R4, R5      ; R4 = 8B + C
LOAD R6, D      ; Load D into R6
ADD R4, R6      ; R4 = X = 8B + C + D
STORE R4, X     ; Store X back to memory

; Calculate Y = X + V
LOAD R7, X      ; Load X into R7
ADD R7, V       ; R7 = Y = X + V
STORE R7, Y     ; Store Y back to memory

In summary, the assembly code varies based on the architecture used. The Reg-Reg architecture focuses on using registers for all operations, while the Reg-Mem architecture allows for direct memory manipulation, which can simplify some operations. Understanding these differences is crucial for efficient programming in assembly language.

ApprovedApproved
Last Activity: 8 Months ago
star
LIVE ONLINE CLASSES

Prepraring for the competition made easy just by live online class.

tv

Full Live Access

material

Study Material

removal

Live Doubts Solving

assignment

Daily Class Assignments