1
votes

new here, and new to assembly.

I am working on my first assignment and it seems simple but i still lack the understanding of MIPS.

My current problem is trying to read the prompts and print the integers. I have to do this with out pseudo instructions (i.e. la, li,...), so I can only use lui, add, addi, sw... Without the pseudo code I am lost because now I have to call the strings by the address, which I am guessing is 0x1001. My other question is how do I move to the next address?

tl;dr...Must be able to compute function val3=$s0-$s1+$s2, where $s0=27, $s1=val1, and $s2=val2 w/o pseudo instructions.

This is just the beginning part of my code and help in English (so I can understand XD) would be appreciated)

.data                       #variable declaration
val1: .word 0                   #0x100100000
val2: .word 0                   #0x100100004
val3: .word 0                   #0x100100008
prompt1: .asciiz    "Mike Rosenfeld"    #0x10010000c
prompt2: .asciiz    "Enter a number"    #0x100100010
prompt3: .asciiz        "\n"        #0x100100012

.space 15

.globl main
.text                       #instructions

 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>START>>>>>>>>>>>>>>>>>>>>>>>>>>
 main:
addi    $s0, $zero, 5           #set command to read 
#syscall                #get value
addi    $a0, $v0, 27            #initialize a = 27
addi    $v0, $zero, 27          #set command to print

  #>>>>>>>>>>>>>>>>>>>>>DEFINE VARIABLES>>>>>>>>>>>>>>>>>>>>>>
#lw $t0, val1           #input value #1
lui $t0, 0x1001         #store value #1  
addi    $a0, $zero, 4           #call string prompt 1
syscall
addi    $v0, $zero, 5
syscall
sw  $v0, 0($t0)
1
Pseudo-instructions are that: pseudo. They always translate to native instructions, so just replace them. See here.m0skit0

1 Answers

0
votes

simply write the code with pseudo-instructions if it is easier at first, then replace each pseudo-instruction by the equivalent TAL instructions:

For example:

li $t0, 5

Can be replaced with:

addi $t0, $0, 5

Finally as a general advice, stay away from absolute addressing, for real-life codes you will practically ALWAYS depend on relative addressing for packaging purposes, or more accurately for your code to be easily shipped around in memory by the OS or any other code (possible self-modifying code in some extreme cases)