MIPS Assembly Language Programming: If Statements, Loops, Procedures 5. (24 pts)
ID: 3861048 • Letter: M
Question
MIPS Assembly Language Programming: If Statements, Loops, Procedures 5. (24 pts) Name your source code file h3-1.8 Let lower and upper be two positive integers with 1 s lower, upper s 10 and lower s upper. Let a and b be two positive integers with lower s a, to s upper and a s b. Let T a b For all pairs of a and b satisfying the specified conditions, find and print the maximal value of r. For example, suppose lower 10 and upper 13. The algorithm will compute T for each a, b pair where 10 s a, b s 13 and a b 10 D 10 10 102 1010 0000 010 10 11 10102 1011 0001 110 10 G 12 1010, e 1100 0110 610 10 13 10102 1101 01.11. 710 11 11 1011 1011 0000 010 11 G 12 1011 e 1100 0111 710 11 D 13 10112 1101 01.10 610 12 12 11002 1100 0000 010 12 G 13 1100 e 1101 0001 110 13 D 13 11012 1101 0000 010 The maximal value of r is 7 when a, b 10, 13 and a, b 11, 12. The output from the program should be 7. Here is the pseudocode for the algorithm which solves this problem, function. mar Tor (lower unsigned int, upper unsigned int unsigned int unsigned int a, b, mar, z for a lower to upper do for b a to upper do if T mare then mar end for end for return mar end function mar TorExplanation / Answer
a.
// pseudo code using two while loops
function max_xor(loower;unsigned int,upper:unsigned int)->unsigned int
unsigned int a,b,max,x
max<-0
a<-lower
while(a!<-upper)
b<-a
while(b!<-upper)
x<-a xor b
if(xx>max then max<-x)
b++
a++
return max
b.
// pseudo code using if and goto statements
function max_xor(lower:unsigned int,upper:unsigned int)->unsigned int
unsigned int a,b,max,x
max<-0
a<-lower
label 1:
if(a<=upper)
b<-a
label 2:
if(b<=upper)
x=a xor b
if(x>max then max<-x)
b++
goto label 2
a++
goto label 1
c.
// assembly language code
MVI A LOWER
MVI C 00
MVI D 00
MOV E,A
LABEL 1: MOV B,A(MOV VALUE IN ACCUMULATOR TO REGISTER B)
LABEL 2: XRA B(XOR VALUE IN ACCUMULATOR WITH B)
LABEL 3: MOVC,A // CODE OF FINDING MAX VALUE
CMP C
JC LABEL 3
INR B
JPE LABEL 2 // JUMP TO LABEL 2 UNTIL B NOT EQUAL TO UPPER
INR E
JPE LABEL 1 // JUMP TO LABEL 1 UNTIL E NOT EQUAL TO UPPER
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.