Given the following segment of a MIPS assembly code and its corresponding machin
ID: 3891748 • Letter: G
Question
Given the following segment of a MIPS assembly code and its corresponding machine code. Fill in the blanks assuming the message1 occupies 33 characters and stored in locations 0x11110000-0x1111020 and message2 follow message1.
Location Machine Code Assembly Program
0x00400000 0x3402 ________ loop: li $v0, -7
0x00400004 0x3c04_________ la $a0, message1
0x00400008 0x1844_________ blez $v0, next
0x0040000c 0x3408_________ li $t0, 2
0x00400010 0x01024020 : add $t0,$t0,$v0
0x00400014 0x1440__________ bnez $v0, loop
0x00400018 0x3c01___________ next: la $a0, messge2
0x0040001c 0x3424_________
Can someone please explain how each assembly code translates to the corresponding machine code?
Explanation / Answer
It is an I-type instruction ,So format is <opcode(6-bits) rs(5 bits) rt(5 bits) immediate(16 bits)>
addiu opcode=0x09 rs=$0 rt =$v0 immediate=2's complement of 7
001001 00000 00000 1111 1111 1111 1001
Convert into hex divide each bits into 4 -bits to convert
0x2402fff9
Convert into pseudocode--> lui $1,higher bits address
ori $a0,$1,lower bit of address
Higher address= 00010001000100001
Lower address= 0001000000100001
oring both we get , 0001000100110001
oring both opcodes, lui opcode=0x0f and ori opcode=0x0d we get,001111
This is an I-type instruction,so format=<opcode(6-bits) rs(5 bits) rt(5 bits) immediate(16 bits)>
001111 00000 0010 0001000100110001
0x3c041131
------------------------------------------------------------------
blez opcode=0x06 rs=$v0 rt=$v0,offset=3("next" label cominf after 3rd instruction)
000101 00010 00010 0000 0000 0000 0011
0x18040003
---------------------------------------------------
Convert into pseudocode-->addiu $t0,$0,2
addiu opcode=0x09 rs=$0 rt =$t0 immediate=2
001001 00000 01000 0000 0000 0000 0010
0x24080002
R-type instruction format <opcode(6bits-000000) rs(5 bits) rt(5 bit)rd(5bits)shampt(5 bits)func(5bits>
000000 01000 00010 01000 00000 100000
0x01024020
-------------------------------------------
Pseudocode-->bne $v0,$v0,loop
bne opcode=0x05
000101 00010 00010 1111 1111 1111 1001(2's complement of 7 , because loop wiillbe backward 7th instruction ,so -7th take 2's complement
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.