0

I am new to MIPS and this assignment is a little confusing for me because the requirement is to calculate the ASCII values of each character in one's name, and to print the name in Last, First format, along with one's student ID number, whose digits must be stored as integers. Here is the question: 1. The digit part of the ID must be printed using the integer-printing system call, the rest must be printed using the single-character-printing system call. 2. The value in $a0 must be calculated based on the old value in $a0, except for loading a value into $a0 at the beginning

Please help me get started with this. Thanks!


.text

main:

jal myLetter

li $v0, 10 

syscall  

myLetter:

li $v0, 4

la $a0, 'A'

syscall  


jal mySecondLetter

li $v0, 10 

syscall  

mySecondLetter:

li $a0, $a0

addi $a0, $a0, 34

sw $a0, $a0

syscall  


jal myThirdLetter

li $v0, 10 

syscall  

myThirdLetter:

li $a0, $a0

addi $a0, $a0, 5

sw $a0, $a0

syscall

jal myFourthLetter

li $v0, 10 

syscall  

myFourthLetter:

li $a0, $a0

addi $a0, $a0, 1

sw $a0, $a0

syscall

jal myFifthLetter

li $v0, 10 

syscall  

myFifthLetter:

li $a0, $a0

addi $a0, $a0, 4

sw $a0, $a0

syscall

jal myCommaOne

li $v0, 10 

syscall  

myCommaOne:

li $a0, $a0

sub $a0, $a0, 65

sw $a0, $a0

syscall

jal mySpace

li $v0, 10 

syscall  

mySpace:

li $a0, $a0

sub $a0, $a0, 12

sw $a0, $a0

syscall

jal myFirstNameLetterOne

li $v0, 10 

syscall  

myFirstNameLetterOne:

li $a0, $a0

addi $a0, $a0, 37

sw $a0, $a0

syscall


jal myFirstNameLetterTwo

li $v0, 10 

syscall  

myFirstNameLetterTwo:

li $a0, $a0

addi $a0, $a0, 49

sw $a0, $a0

syscall


jal myFirstNameLetterThree

li $v0, 10 

syscall  

myFirstNameLetterThree:

li $a0, $a0

sub $a0, $a0, 12

sw $a0, $a0

syscall

jr $ra
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
EAP
  • 31
  • 1
  • 8
  • Your program doesn't need to "calculate" ASCII codes; the assembler will do that for you when you write `.asciiz "Eva"`, assembling the 3 bytes of ASCII codes into your object file. You can load each one into integer registers using an `lbu` instruction to load that byte. And yes, looping with a pointer-increment until you get to the terminating `0` byte is exactly what you'd want to do. – Peter Cordes Oct 13 '18 at 23:40
  • Thanks! However, the professor doesn't want us to use strings. He wants us to print our names using individual characters. Is there any way I can do it without .asciiz? – EAP Oct 14 '18 at 19:15
  • Sure, you can use `li $a0, 'E'` to put the ASCII code for the letter E into a 32-bit register. It assembles to the same machine code as `li $a0, 0x45`. http://www.asciitable.com/, because `'E'` is an integer constant. Or you can use `.byte 'E', 'v', ..., 0` to put them in data memory instead of as immediates if you need to loop over them. Using decimal or hex numbers instead of character literals is exactly equivalent, but less convenient because you have to look it up by hand. – Peter Cordes Oct 14 '18 at 19:19
  • Thanks! I started my program. As I said, this is my first MIPS program, besides the Hello World one and I am not sure how to fix it. Could you please tell me what to fix? – EAP Oct 14 '18 at 21:55
  • Here it is:main: jal myLetter li $v0, 10 syscall myLetter: li $v0, 4 la $a0, 'A' syscall jal mySecondLetter li $v0, 10 syscall mySecondLetter: li $a0, $a0 addi $a0, $a0, 34 sw $a0, $a0 syscall jal myThirdLetter li $v0, 10 syscall myThirdLetter: li $a0, $a0 addi $a0, $a0, 5 sw $a0, $a0 syscall jal myFourthLetter li $v0, 10 syscall myFourthLetter: li $a0, $a0 addi $a0, $a0, 1 sw $a0, $a0 syscall – EAP Oct 14 '18 at 21:57
  • myCommaOne: li $a0, $a0 sub $a0, $a0, 65 sw $a0, $a0 syscall jal mySpace li $v0, 10 syscall mySpace: li $a0, $a0 sub $a0, $a0, 12 sw $a0, $a0 syscall jal myFirstNameLetterOne li $v0, 10 syscall myFirstNameLetterOne: li $a0, $a0 addi $a0, $a0, 37 sw $a0, $a0 syscall jal myFirstNameLetterTwo li $v0, 10 syscall myFirstNameLetterTwo: li $a0, $a0 addi $a0, $a0, 49 sw $a0, $a0 syscall jal myFirstNameLetterThree li $v0, 10 syscall myFirstNameLetterThree: li $a0, $a0 sub $a0, $a0, 12 sw $a0, $a0 syscall jr $ra – EAP Oct 14 '18 at 21:59
  • I hope you realize those comments are entirely unreadable. [edit] your code into your question if you want any help debugging it. (See [mcve]. Find out what you can with a debugger and include that in your question, too.) – Peter Cordes Oct 14 '18 at 22:43
  • Sorry. I will post it as an answer to my question. Thanks for helping me! – EAP Oct 14 '18 at 22:56

0 Answers0