Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Convert the following high-level code into assembly instructions and then int

ID: 3912158 • Letter: A

Question

a. Convert the following high-level code into assembly instructions and then into machine instructions of the CS264 processor described in the class. Assume the values of the variables A and C have been already stored in memory and that the first machine instruction of the code is stored in location 00010

                      

start:             while ( C< 0)

                      {                                

                            if (A >= 0) C= C- A

                           

                            A=C *A

                      }

                      B= C+ A

                       End

b. Describe the microinstructions and or steps needed to retrieve and execute each of the eight instructions.

Explanation / Answer

Convert program to assembly and genarate machine code

Assembly code

#t0=C,$t1=A and $t2=B
start:
    #while(C<0)

     slti $1,$t0,0

     bne $1,$0,if
ret:
     #B=C+A
     add $t2,$t0,$t1
end:
     #End of the program
    addiu $v0,$0,10
    syscall
if:
    #if(A>=0)
    slti $1,$t1,0
    beq $1,$0,next
    #A=C*A
    mul $t1,$t0,$t1
    #return to while loop
    j start
next:
   #C=C-A
   sub $t0,$t0,$t1
   #return to while loop
   j start

------------------------------------

Machine instruction

              I -type instruction(format-->opcode(6bit) rs(5bit) rt(5 bit) immediate(16 bit)

              opcode(oxoa-->001010)rs($t0-->01000)rt($1-->00001)immediate(0000 0000 0000 0000)

             Convert into hex-->0x29010000

                I -type instruction(format-->opcode(6bit) rs(5bit) rt(5 bit) immediate(16 bit)

              opcode(oxoa-->001010)rs($1-->00001)rt($0-->00000)immediate(0000 0000 0000 0003)

             Convert into hex-->0x14200003

            R-type (format-->opcode(6bit->000000)rs(5bit-->$t0-->01000)rt(5 bit-->$t9-->01001)rd(5bit-->$t2-->01010)shampt(0)funct(0x20)

    Convert to hex-->0x01095020

              I -type instruction(format-->opcode(6bit) rs(5bit) rt(5 bit) immediate(16 bit)

              opcode(oxo9-->001001)rs($0-->00000)rt($v0-->00010)immediate(10-->0000 0000 0000 1010)

             Convert into hex-->0x2402000a

                  0x0000000c

              I -type instruction(format-->opcode(6bit) rs(5bit) rt(5 bit) immediate(16 bit)

              opcode(oxoa-->001010)rs($t1-->01000)rt($1-->00001)immediate(0000 0000 0000 0000)

             Convert into hex-->0x29210000

                I -type instruction(format-->opcode(6bit) rs(5bit) rt(5 bit) immediate(16 bit)

              opcode(oxo4-->000010)rs($1-->00001)rt($0-->00000)immediate(0000 0000 0000 0002)

             Convert into hex-->0x10200002

              R-type (format-->opcode(6bit->011100)rs(5bit-->$t0-->01000)rt(5 bit-->$t1-->01001)rd(5bit-->$t1-->01010)shampt(0)funct(0x02)

    Convert to hex-->0x71094802

                J type(opcode(6bit-->000010) target(26bit given that00010)

              hex-->0x08000010

            R-type (format-->opcode(6bit->000000)rs(5bit-->$t0-->01000)rt(5 bit-->$t1-->01001)rd(5bit-->$t0-->01000)shampt(0)funct(0x22)

hex-->0x01014022

                J type(opcode(6bit-->000010) target(26bit given that00010)

              hex-->0x08000010

---------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote