mips-linux-gun-as and mips-linux-gnu-ld compile mips failed - linux

I use the mips-linux-gnu-as and mips-linux-gun-ld compile the mips assembly code! The code is here!
.data
message: .asciiz "Hi, everybody.\nMy name is Alchemist.\n"
.text
main:
jal displayMessage
addi $s0, $zero, 5
li $v0, 1
add $a0, $zero, $s0
syscall
# Tell the program that the program is done
li $v0, 10
syscall
displayMessage:
li $v0, 4
la $a0, message
syscall
jr $ra
2.Then i compile the mips asseebe on ubuntu 18.04 TLS!This is my error:
mips-linux-gnu-ld: warning: cannot find entry symbol __start; defaulting to 00000000004000f0
3.How can i due to this error?
Thanks!!

Related

How do I read a string from terminal input in Linux MIPS32 assembly?

I'm currently learning MIPS programming in my university for the MARS simulator. However, I wanted to try to learn to write MIPS assembly programs for a MIPS Linux virtual machine. I managed to create a MIPS32 Debian 11 virtual machine. However, I having trouble with the Linux kernel system calls and their parameters. After some confusion, and a long time of searching the internet, I managed to create a basic hello world program. Then, I tried to create a program that would ask the user for some text, and then print it out, but it doesn't work.
I'm expecting something like this:
Please enter a string: This is text
The input is: This is text
However, I get:
Please enter a string: This is text
The input is:
My code is:
.data
prompt: .asciiz "Please enter a string: "
promptLength: .quad . - prompt
input: .space 81 #Create a 80-character empty string
inputLength: .word 80
answer: .asciiz "The input is: "
answerLength: .quad . - answer
newline: .asciiz "\n"
.text
.globl __start
__start:
#Display the prompt
li $a0, 1
la $a1, prompt
lw $a2, promptLength
li $v0, 4004
syscall
#Read the input
li $a0, 1
la $a1, input
lw $a2, inputLength
li $v0, 4003
syscall
move $s0, $v0
#Write the user input
li $a0, 1
la $a1, answer
lw $a2, answerLength
li $v0, 4004
syscall
la $a1, input
move $a2, $s0
syscall
#Exit
b exit
printNewline:
li $a0, 1
li $a1, newline
li $a2, 1
li $v0, 4004
syscall
jr $ra
exit:
li $v0, 4001
syscall
PS. Is there any book/YouTube tutorial/website that teaches MIPS programming for Linux?

Separate words of the string and store them in stack in MIPS

.data
string: .asciiz "Please enter the string : "
newLine: .asciiz "\n"
buffer: .space 100
.text
.globl main
main:
la $a0, string
li $v0, 4
syscall
li $v0, 8
la $a0, buffer
li $a1, 100
syscall
la $t0, buffer
li $t0, 0
subu $sp, $sp, 4
li $v0, 4
syscall
Here above is beginning of the my code. And I need to separate each words of the string and then store them in the stack. First I tried to store word in stack as allocation memory with stack pointer and it works now. But I need to store each word(not characters) of the sentence such as
Hello I am Furkan
So for this example there should be 4 words in stack.
Hello
I
am
Furkan
How can I solve that ?

MIPS Runtime exception and Address out of range

Hello I am trying to write this code for a project and at the end of the code I am getting the error "line 84: Runtime exception at 0x004000dc: address out of range 0x0000006e" I am new to MIPS and can not figure out how to resolve this. The purpose of the code is for a user to enter a string and manipulate as they desire and to print the new string at the end. Any help??
.data
Prompt1: .asciiz "Your current string is: \n"
Prompt2: .asciiz "\nDo you want to make any changes to the string? (Y/N) \n"
Prompt3: .asciiz "\nEnter the character in the string would you like replaced: \n"
Prompt4: .asciiz "\nEnter what you would like to change the character to: \n"
Prompt5: .asciiz "\nYour final string is: "
Word: .space 40
yes: .asciiz "y"
.text
#######################
#Print Instructions
li $v0, 4
la $a0, Prompt1
syscall
#getting text from the user
li $v0, 8 #print string
la $a0, Word
li $a1, 40
syscall
#########################
Loop:
#yes or no
li $v0, 4
la $a0, Prompt2
syscall
li $v0, 8 #get input
la $a0, Word
li $a1, 2
move $t0, $a0 #save string to $t0
syscall
lb $t1, yes
lb $t0, 0($t0)
bne $t0, $t1, endloop
#replace char
li $v0,4
la $a0, Prompt3 #replace char message
syscall
li $v0, 12 #read in char
syscall
addi $s0, $v0, 0 #store char in $s0
li $v0, 4
la $a0, Prompt4 #new char message
syscall
li $v0, 12
syscall
addi $s1, $v0, 0 #store new char in $s1
la $t0, Word
li $t1, -1
j Loop
replaceLoop:
lbu $t2, 0($t0) #load our input's first char is at
addi $t0, $t0, 1 #increment address of our string.
addi $t1, $t1, 1
beq $t2, $s0, replace #check if char in input, matches
beq $t2, $0, endloop #char we want to replace.
replace:
sb $s1, -1($t0)
b replaceLoop
endloop:
li $v0, 4
la $a0, Prompt5
syscall
li $v0, 4
la $a0, ($t0)
la $a1, 40
syscall
#exit program
li $v0,10
syscall

MIPS, how to get 5 strings from console and then print them out

# Data section
.data
insert1: .word 20 # make space in memory for a word with address insert1
insert2: .word 20
insert3: .word 20
insert4: .word 20
insert5: .word 20
Input: .asciiz "Enter a Series of 5 formulae\n"
Output: .asciiz "The values are:\n"
CR: .asciiz "\n"
# Text Section
.text
.globl my_main
my_main:
la $a0, Input
li $v0, 4
syscall
la $a0, insert1 # sets $a0 to point to the space allocated for writing a word
la $a1, insert1 # gets the length of the space in $a1 so we can't go over the memory limit
li $v0, 8
move $t0, $a0
syscall
la $a0, insert2
la $a1, insert2
li $v0, 8
li $v0, 8
move $t1, $a0
syscall
la $a0, insert3
la $a1, insert3
li $v0, 8
li $v0, 8
move $t2, $a0
syscall
la $a0, insert4
la $a1, insert4
li $v0, 8
li $v0, 8
move $t3, $a0
syscall
la $a0, insert5
la $a1, insert5
li $v0, 8
li $v0, 8
move $t4, $a0
syscall
la $a0, Output
li $v0, 4
syscall
la $a0, insert1
li $v0, 4
syscall
la $a0, insert2
li $v0, 4
syscall
la $a0, insert3
li $v0, 4
syscall
la $a0, insert4
li $v0, 4
syscall
la $a0, insert5
li $v0, 4
syscall
# Exits Program
li $v0, 10
syscall
Results I'm getting:
Enter a Series of 5 formulae:
hey
man
how
are
you
The values are:
hey
man
how
are
you
man
how
are
you
how
are
you
are
you
you
Results I want:
Enter a Series of 5 formulae:
hey
man
how
are
you
The values are:
hey
man
how
are
you
So basically I need to take 5 strings from the console and then print out as seen above. Weirdly enough when I use words that are only 1 letter long it prints out correctly but anything else other than single letters returns a sequence of words similar to what I've shown above. I'm new to MIPS and not sure what I'm doing wrong here. Any help would be appreciated thanks.
EDIT: It seems I just needed to use .space instead of .word. Thanks to those who commented/answered the question for helping out.

MIPS: Printing string with no pseduo instructions

Below I have
.globl main
.data
prompt:
.asciiz "Hello world!"
.text
main:
addi $v0, $v0, 4
lui $a0, 0x1000
syscall
rtn:
jr $ra
Now, I'm not sure why the string is not printing, it runs without syntax errors. Also, I am not permitted to use any pseudo-instructions, so that is why I am doing this the slightly longer way. That is where the error is coming in, I do not know where the prompt string is being stored? Any help is appreciated!
Thanks!
In SPIM, the .data section starts at address 0x10010000 by default. So to print the Hello World string without using pseudo-instructions you could use this:
.globl main
.data
prompt:
.asciiz "Hello world!"
.text
main:
addi $v0, $zero, 4
lui $a0, 0x1001 # $a0 = 0x10010000
syscall
rtn:
jr $ra
Note that if the address is 0x1000, that means the upper 16 bits are all zero, and the bottom 16 bits are 0x1000. You are loading the upper 16 bits. So instead of lui $a0, 0x1000 try addiu $a0, $0, 0x1000
However, your assembler's symbol manipulation expressions shouldn't count as pseudo-instructions, so something like this GAS code (or the equivalent in your assembler) should also be allowed:
lui $a0, %hi(prompt)
ori $a0, $a0, %lo(prompt)

Resources