1)
Here we have the part that allow to introduce data in our program. For example,
if we want to introduce some data in the form in an
array in java we use the following instruction:
char str1[] = {'
P','l','e','a','s','e',' ','e','n','t','e','r',' ','a','...
}
We can declare the same array using the "
.asciiz" command in assembler
after the command .data. Depending of the kind of data
we are using we have the following command
s to introduce data:
.float
//float values
.word
//integers types
.byte //byte types
.asciiz //text data
An example of their use are
.float 1.23, 1.34, 1.2
# array of floats
.word 1, 2,
3, 4, 5, 6 # array of integers
.data
str1: .asciiz " Please enter a number >=
1 : "
str2: .asciiz "\n\n The result is:"
2)
It is always necessary to declare where the
text file starts. For that, we use the command "
.text". in addition is a good idea to declare
what section is going to be our global main.
For that, we use the command ".globl
[name of main]"
.text
.globl main
main:
---------2.a---------
Here we have a call
to a macros that allows us to print text in the terminal
li $v0, 4
la $a0, str1
syscall
----------------------
li $v0, 5
syscall
move $t1, $v0
addi $t3, $zero,
1
slti $t2, $t1,
1
beq $t3, $t2,
do_nothing
addi $t0, $t0,
0
---------2.b---------
Here we have a really interesting
structure that represents the classical loops in our high level languages.
Different Loops will have different structures in assembler.
loop:
sge $t2, $t1,
$t3
beq $t2, $zero,
end
add $t0, $t0
, $t1
addi $t1, $t1
, -1
j loop
end:
----------------------
li $v0, 4
la $a0, str2
syscall
li $v0, 1
move $a0, $t0
syscall
do_nothing:
---------2.c-----------
It is always a good idea
to have this instructions to finish and return after our program finishes.
li $v0, 10
syscall
-----------------------