mars-simulator

invalid program counter value: 0

拟墨画扇 提交于 2019-12-04 04:53:59
问题 I'm currently working with assembly language under the MIPS processor. I'm currently using MARS simulator and for reasons unknown I get the following error message after every run: Go: running try.s Error in : invalid program counter value: 0 Go: execution terminated with errors. I get this error message independent of the code I'm using, just wondering if this is a bug in the MARS simulator or if it's something I'm missing. 回答1: You probably finish your program with a jr $ra (return to

String to int conversion and String manipulation MIPS

雨燕双飞 提交于 2019-12-02 10:49:19
For my homework I need to use MIPS to take an input with an arbitrary letter at the front followed by numbers(e.g. x123) and add 5 to the number then print out the final number (from the example the output would be 128) Jonathon Everatt .data entmsg: .asciiz "Enter a string:\n" ui1: .space 20 counter: .space 20 outmsg: .asciiz "The value +5 is:\n" .text main: #Printing the message li $v0, 4 la $a0, entmsg syscall #Saving the text li $v0, 8 la $a0, ui1 li $a1, 20 syscall #Count the length of the string la $t0, ui1 # la means load address (so we load the address of str into $t0) li $t3, 0 # $t1

How to change the assembly code %hi and %lo to run in 'MARS'?

烂漫一生 提交于 2019-12-02 08:33:48
I used 'compiler explorer' to convert c++ to MIPS but it doesn't work well in the MARS because of %hi and %lo I know I should change the part, but I don't know how to change... Please help $L5: lui $2,%hi($LC1) lwc1 $f0,%lo($LC1+4)($2) lwc1 $f1,%lo($LC1)($2) b $L3 $LC1: .word 1100470148 .word 0 $L17: lw $2,16($fp) addiu $3,$2,1 sw $3,16($fp) lui $4,%hi(savepath) sll $3,$2,2 addiu $2,$4,%lo(savepath) addu $2,$3,$2 li $3,1 # 0x1 sw $3,0($2) move $sp,$fp lw $fp,36($sp) addiu $sp,$sp,40 j $31 AFAIK, there is no way in Mars to have something like the gas %lo(label) or %hi(label) feature. A simple

invalid program counter value: 0

老子叫甜甜 提交于 2019-12-02 00:22:25
I'm currently working with assembly language under the MIPS processor. I'm currently using MARS simulator and for reasons unknown I get the following error message after every run: Go: running try.s Error in : invalid program counter value: 0 Go: execution terminated with errors. I get this error message independent of the code I'm using, just wondering if this is a bug in the MARS simulator or if it's something I'm missing. You probably finish your program with a jr $ra (return to caller). However, the code executed by MARS doesn't have a caller - it's executed at startup and has no function

MIPS Help: Recursive Functions

家住魔仙堡 提交于 2019-12-01 14:39:12
I'm trying to code this recursive function into MIPS. My problem is I'm not sure how I can do the recursive step. I'm pretty sure I got the rest correct. int recur(int n) { if(n == 1 || n == 2) { return 2; } else { return (n-4)+n*recur(n-2); } } .data promptMessage: .asciiz "Enter a number that is greater than or equal to 0: " resultMessage: .asciiz "\nThe answer is: " input: .word 0 answer: .word 0 .text .globl main main: #Read the number from the user li $v0, 4 la $a0, promptMessage syscall li $v0, 5 syscall sw $v0, input #Call the function lw $a0, input jal recur sw $v0, answer #Display

MIPS Help: Recursive Functions

ぐ巨炮叔叔 提交于 2019-12-01 12:25:41
问题 I'm trying to code this recursive function into MIPS. My problem is I'm not sure how I can do the recursive step. I'm pretty sure I got the rest correct. int recur(int n) { if(n == 1 || n == 2) { return 2; } else { return (n-4)+n*recur(n-2); } } .data promptMessage: .asciiz "Enter a number that is greater than or equal to 0: " resultMessage: .asciiz "\nThe answer is: " input: .word 0 answer: .word 0 .text .globl main main: #Read the number from the user li $v0, 4 la $a0, promptMessage syscall

How to load memory address without using pseudo-instructions?

时间秒杀一切 提交于 2019-11-29 11:04:28
I'm trying to learn MIPS assembly language by myself using MARS simulator . For didactic reasons I'm limiting myself to not using pseudo-instructions. While trying to get the address of some data into a register, I ran into a problem because I cannot use la . I tried using lui in combination with ori , the same as if I was to load a number directly, to no avail: .data arr: .byte 0xa1 .byte 0xb2 .byte 0xc3 .byte 0xd4 .byte 0xe5 .byte 0xf6 .byte 0x7a .byte 0x8b .byte 0x9c .byte 0xad .text lui $s0, mem # <--- mars just gives me errors here :( ori $s0, mem # ?? ... Is this doable using

How do I return a value from the main function in MIPS?

拜拜、爱过 提交于 2019-11-28 10:36:59
问题 Say I want to write the following C program in MIPS: int main () { return 5; } When I try the following MIPS code in MARS: main: ADDI $v0, $zero, 5 # $v0 = 5 JR $ra # return from main() I get a 'invalid program counter' error. This is apparently because you cannot jump out of the main function in MARS. So I tried rewriting it like so: main: ADDI $v0, $zero, 5 # $v0 = 5 li $v0, 10 # load 10(exit) for syscall syscall # exit After executing this, the $v0 register contains the value 10, not 5.

How to load memory address without using pseudo-instructions?

断了今生、忘了曾经 提交于 2019-11-28 04:21:28
问题 I'm trying to learn MIPS assembly language by myself using MARS simulator . For didactic reasons I'm limiting myself to not using pseudo-instructions. While trying to get the address of some data into a register, I ran into a problem because I cannot use la . I tried using lui in combination with ori , the same as if I was to load a number directly, to no avail: .data arr: .byte 0xa1 .byte 0xb2 .byte 0xc3 .byte 0xd4 .byte 0xe5 .byte 0xf6 .byte 0x7a .byte 0x8b .byte 0x9c .byte 0xad .text lui

Is mars MIPS simulator Big or Little Endian

Deadly 提交于 2019-11-27 04:48:36
问题 I have to determine if the mars simulator is big or little endian as homework, this seems pretty straightforward at first, but I am having some issues. First I tried storing 4 bytes in memory with .byte 0, 0, 0, 1, in memory this appears as 0x01000000, so, in reverse order, which seems to indicate that the simulator is little endian, however, when I load the 4 bytes as an integer to a register, what appears in the register is 0x01000000 again, as I understand if it was little endian what