spim

QtSPIM: Explanation for code shown without loading program

南笙酒味 提交于 2020-03-05 04:06:31
问题 The QtSPIM MIPS assembler already shows some lines of code even though there is no program loaded, like can be seen on https://ecs-network.serv.pacific.edu/ecpe-170/tutorials/qtspim-tutorial. I assume this is required for loading programs, but I would be very interested in an exact explanation to understand all details. 回答1: A QtSPIM program consists of two parts: an exception handler, and a user program. The default exception handler includes both a short user-mode startup code sequence

Mips Output syscall

 ̄綄美尐妖づ 提交于 2020-01-17 11:14:04
问题 li $s5, 2 add $a0, $s5, $0 li $v0, 4 syscall Why system out is (null) in spim ? 回答1: Looks like you are trying to print an int, but the system call code you are providing stands for "print string". As you have no label called 2 (hence no string starting at address of label 2 ), the console prints out (null) . Try this li $a0, 2 #integer to be printed li $v0, 1 #system call code 1: print_int syscall Now it should print 2 Check out this table for syscall op codes. 来源: https://stackoverflow.com

using multiple mips arguments >4

空扰寡人 提交于 2019-12-24 09:25:10
问题 Im trying to program a function to use extra arguments besides 4 (since my version of mips only supports $a0-$a3) by pushing them on the stack, but my code is incorrect. Here is my code in main (snippet): li $t0,40 #temp value for our 5th arg. addi $sp, $sp, -4 #decrement stack pointer by 4 sw $t0, 0($sp) #save the value of $t0 on the stack. jal printf which sets a temporary value of 40, gives space on the stack, and saves it. My function is then called. As a test to see if this worked,

MIPS Dynamic Memory Allocation using sbrk

大兔子大兔子 提交于 2019-12-23 20:32:24
问题 I was trying to use sbrk for dynamic memory allocation. But, being a new comer to SPIM and MIPS, I was unable to do so. I sketched out a rough code for the same. . data var: .word 25 .text main: li $v0, 9 la $v0, var lw $a0, var syscall # DYNAMICALLY ALLOCATING MEMORY OF SIZE 4 BYTES AT ADDRESS OF VAR sw $v0, var li $v0, 10 syscall 回答1: .data var: .word 25 .text main: li $v0, 9 lw $a0, var syscall # DYNAMICALLY ALLOCATING MEMORY OF SIZE 4 BYTES AT ADDRESS OF VAR sw $v0, var li $v0, 10 syscall

Storing values in HI and LO registers of MIPS

久未见 提交于 2019-12-22 08:08:02
问题 I am writing certain code in MIPS and I've come to the point where the requirement is to store the result, temporarily, in HI and LO special registers (both are 4 bytes wide). These instructions are at my disposal: divu s,t lo <-- s div t ; hi <-- s mod t multu s,t hi / lo < -- s * t ; So, divu stores result of division in LO and remainder in HI , while multu stores result of multiplication in LO (lower 4 bytes) and HI (higher 4 bytes). Later, to retrieve result from HI and LO registers, I

Use of Frame Pointer MIPS

耗尽温柔 提交于 2019-12-19 10:41:11
问题 i need to convert my code from stack pointer to only use frame pointer, how can i do so? i am very new to MIPS. i have this recursion C code and its MIPS code below. i am using stack pointer , how can i change it to use frame pointer? here is my C Code int fact(int n) { if(n!=1) return n*factorial(n-1); } int comb (int n, int k) { return fact (n) / fact (k) / fact (n - k); } here my MIPS code comb: sub $sp, $sp, 16 sw $ra , 0($sp) sw $s0, 4($sp) sw $a0, 8($sp) sw $a1, 12($sp) jal fact move

MIPS questions about writing assembly to call functions on an array

亡梦爱人 提交于 2019-12-13 16:26:37
问题 I currently am taking a course in assembly and am having trouble with the following assignment. Write a program that reads (with an appropriate prompt) a sequence of 20 integers and stores them in an array, and then calls the following three functions and prints the results in a readable format. The three functions are: smallestLargest: computes the smallest and the largest values in the array. divisible: computes the number of integers in the array which are divisible by 4 SumProduct:

Print MIPS Register Contents

拥有回忆 提交于 2019-12-13 02:48:25
问题 I am trying to print an unsigned integer value from a MIPS register as ASCII text to the console. In other words, let's pretend $a0 has "0x4ab3c823" in it. I want to print out "4ab3c823" to console in xSPIM. Here is my attempt. I keep getting the decimal values, not the ASCII. It's only a snipped of the entire program, so I cut out the rest. .data printspace: .space 8 .text printHex: move $t0,$a0 la $a0,printspace #Save address of 8 blank bytes to $a0 sw $t0,0($a0) #Copys the integer I want

Show division result in MIPS

眉间皱痕 提交于 2019-12-11 23:20:10
问题 Merged with Use the floating point instructions to get results in decimal. Hi I'm coding a small program in MIPS and I have this code li $v0, 2 div $t0,$t2,$t1 move $a0,$t0 syscall (it's not the full code, just the section handling division) Where $t1 is 2, $t2 is 9. So, 2/9 is 0.2222222222222222 But when I run it I only get 0.0 Why?, how I show the true result? Thanks in advance. 来源: https://stackoverflow.com/questions/6513610/show-division-result-in-mips

MIPS “Unaligned address, Exception 5” error

本小妞迷上赌 提交于 2019-12-11 10:01:58
问题 I'm a noob using SPIM MIPS simulator. I get the error in title X 26 times, when I try to initialize an array of 26 words to 0. I've isolated the problem to be the store word operation sw $t0, 0($s3) , but have no clue what am I doing wrong. The code: .data theArray: .space 104 theArraySz: .word 26 .text .globl main main: move $t0, $zero la $s3, theArray lw $s4, theArraySz add $t2, $zero initLoop: beq $t2, $s4, initEnd sw $t0, 0($s3) addi $s3, $s3, 4 addi $t2, $t2, 1 j initLoop initEnd: jr $ra