Using any of the assembly language instructions shown in Figure 6.5, translate t
ID: 3725422 • Letter: U
Question
Using any of the assembly language instructions shown in Figure 6.5, translate the following algorithmic operations into assembly language code. Show all necessary .DATA pseudo-ops. You may put in whatever initial values you want for a, b, c, and n.
A) Set a to the value of (c + 1) (b c)
B) if b < 0 then Set c to the value of 1 Set c to the value of c + c
C) Set c to the value of 0 for a = 1 to n do if a < 6 then Set c to the value of c + a else Set c to the value of c a Set c to the value of c b
FIGURE 6.5 Binary Op CodeOperation Meaning CON(X) R R-CON(X) 0-CON(X) 0001 0010 0011 0100 0101 0110 0111 LOADX STORE X CLEARX ADD X INCREMENT X SUBTRACTX DECREMENT X COMPAREX CON(X) + 1 CON(X) R-CON(X) R if CONX)>R then GT-1 ese0 ifCOn(X) = R then EQ 1 else 0 1000 1001 1010 1011 1100 1101 JUMP X JUMPGT X JUMPEQX JUMPLT X JUMPNEQX Get the next instruction from memory ocationX Get the next instruction from memory location X if G-1 Get the next instruction from memory location X if EQ 1 Get the next instruction from memory location X if LT 1 Get the next instruction from memory location X if EQ 0 Input an integervalue from the standard input device and store into memory cell X Output, in decimal notation, the value stored in memory cell X Stop program execution. INX 1110 OUT XExplanation / Answer
1.
.data
a DB 0
b DB 4
c DB 10
.code
LOAD b, r1
LOAD c,r2
SUBTACT r1,r2 ; b = b-c
ADD r2,1 ; c=c+1
SUBTACT r2,r1 ; c = c+1 - (b-c)
STORE r2,a ; store result in a
2.
.data
b DB 100
c DB 10
.code
LOAD b,r1
COMPARE r1,0
JUMPLT LT
JUMP GE
LT:
STORE -1,c
JUMP EXIT
GE:
ADD c,c
EXIT:
3.
.data
a DB 0
b DB 4
c DB 10
n DB 5
.code
STORE 0,c ; set c to 0
;now iterate from 1 to n
LOOP:
COMPARE a,n ; loop exit condition
JUMPGT EXIT ; if a>n then jump to EXIT
COMPARE a,6
JUMPLT LT
JUMP GE
LT:
ADD c,a ; c = c+a
ADD a,1 ; increment a
JUMP LOOP
GE:
SUBTACT c,a ; c=c-a
ADD a,1 ; increment a
JUMP LOOP
EXIT:
SUBTACT c,b ; set c to c-b
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.