0
我正在編寫一個程序,在該程序中循環訪問代碼並計算I,J和R類型指令的數量。我將如何去訪問指令的操作碼?MIPS - 訪問指令地址以獲得操作碼
我正在編寫一個程序,在該程序中循環訪問代碼並計算I,J和R類型指令的數量。我將如何去訪問指令的操作碼?MIPS - 訪問指令地址以獲得操作碼
.data
typeR: .word 0x00 #for all TypeR opc code
typeJ: .word 0x01 #we will have to left shit one bit when comparing
typeI: .word 0x11 #this is a dummy value because if it's not R or J, it is I
numR: .word 0
numJ: .word 0
numI: .word 0
endProgram: .word 0x11111111 # you would have to know the address of the #last instruction. Assume for now
.text
main:
lw $s0, countR
lw $s1, countJ
lw $s2, countI
#here you load the address of the first instruction of the program you try
#to loop though say 0x00000000
la $t0, 0x00000000
#here load the instruction code in 0x11111111 to register $t1
lw $t1, endProgram
Loop:
lw $s3, 0($t0) # load first instruction code to $s3
beq $s3, typeR, R #if equal goes to R
sll $s3, $s3, 1 # so we get rid of the first digit
beq $s3, typeJ, J # if equal got to J
J I # this is the else
R:
addi $s0,$s0, 1 #increment countR
j next
J:
addi $s1, $s1, 1#increment countJ
j next
I:
addi $s2, $s2, 1 # increment countI
j next
next:#check if it is the end yet, if not keep going to next instruction
lw $s5, 0($t1)
beq $s5, $t1, exit # if it is last instructin go to exit
#if not keep going
addi $t1, $t1, 4 #move to next instruction since each is 4 byte
j loop
exit:
# I think the last part is pretty simple, depend on what you want to do just #print it out or something, so I've save some typing.
我的不好,我忘了格式化爲代碼。 –
通過讀取其中代碼位於存儲器中,然後進行解碼基於在_MIPS32™架構中的信息對於程序員每個指令字II 卷:該MIPS32™指令SET_。 – Michael