0

Here are my problems with my code: slt $2, $2, 91. slt Rd, R1, R2 The destination register, Rd, is set to 1 if the first source register, R1 is less than the second source register, R2 If you want to compare to the ASCII hexadecimal value for 'Z' you would need to put that hex into a register first. That hex is 0x5A.

I'm confused as to which one is the slt Rd, R1, R2. For li $2,65 # 0x41 I should change this to 0x5A because I want to compare that with the start of the alphabet?

Here is my code:

.data
$LC0:
.ascii "%c \000"
.text

main:
addiu $sp,$sp,-40
sw $31,36($sp)
sw $fp,32($sp)
move $fp,$sp
li $2,65 # 0x41
sw $2,24($fp)
b $L2
nop

$L3:
lw $5,24($fp)
lui $t1, 100
addiu $t1,$t2,-100
jal printf
nop

lw $2,24($fp)
nop
addiu $2,$2,2
sw $2,24($fp)
$L2:
lw $2,24($fp)
nop
slt $2,$2,91 # Having issues with this line of code
bne $2,$0,$L3
nop

move $2,$0
move $sp,$fp
lw $31,36($sp)
lw $fp,32($sp)
addiu $sp,$sp,40
jr $31
nop
Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • It is quite evident that you used some sort of compiler to obtain this assembly code. The start of the alphabet is 'A' or 'a' whose ASCII codes are 65 and 97 (or in hexadecimal 0x41 and 0x61) – gusbro Nov 14 '22 at 16:37
  • Pro tip: don't mix friendly register names (like $a0, $sp, $t0, $s0) with unfriendly register numbers (like $2 $4). Stick with the friendly register names. – Erik Eidt Nov 14 '22 at 16:42
  • `slt` takes 3 registers as operands. `slti` take 2 registers and a constant as operands. Some assemblers might allow `slt` to take that constant instead of a 3rd register, but others will require use of the `slti` opcode. – Erik Eidt Nov 14 '22 at 16:47
  • 1
    Also, that `printf` won't run properly as there's typos in that `lui` code sequence. Yet, MARS doesn't have `printf` in any case, so you'll need to substitute with `syscall` that prints integer or syscall that prints string. – Erik Eidt Nov 14 '22 at 17:02
  • 1
    Also, consider using optimization when compiling C to MIPS assembly or else there will be lots of unnecessary junk in the compiler's output. – Erik Eidt Nov 14 '22 at 17:08
  • Does this answer your question? [Tweak mips-gcc output to work with MARS](https://stackoverflow.com/questions/13052444/tweak-mips-gcc-output-to-work-with-mars) – Erik Eidt Nov 14 '22 at 18:15

0 Answers0