qtspim

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:

MIPS Assembly Alignment Align n

此生再无相见时 提交于 2019-12-11 02:32:42
问题 What does the directive .align n do in an array? To be more specific let's say that I have the following part of code: array: .align 2 .space 800 What's its importance and why not just skip it and use .space 800 This is a school's assignment theory question. 回答1: Taken directly from MARS helping tooltips: Align next data item on specified byte boundary (0=byte, 1=halfword, 2=word, 3=double) Consider this code la $t0, array .data .space 3 array: .space 12 This is assembled into lui $at, 0x1001

Generate random integer in MIPS which compiles with QtSpim

青春壹個敷衍的年華 提交于 2019-12-08 08:57:27
问题 So I've seen a lot of questions on generating random integers in a MIPS program using MARS and syscall 42 and that's ok. The problem is that I need to generate a random integer for a program compiled with QtSpim , which has no syscall for 42 or however for calls greater than 17. I can't figure out getting something like a random value from the system like syscall 30 in MARS which gives the system time. Is there a way to get a random address or hex value to use for a random int generator using

Generate random integer in MIPS which compiles with QtSpim

怎甘沉沦 提交于 2019-12-07 18:09:26
So I've seen a lot of questions on generating random integers in a MIPS program using MARS and syscall 42 and that's ok. The problem is that I need to generate a random integer for a program compiled with QtSpim , which has no syscall for 42 or however for calls greater than 17. I can't figure out getting something like a random value from the system like syscall 30 in MARS which gives the system time. Is there a way to get a random address or hex value to use for a random int generator using xor operations ? Any help would be appreciated. 来源: https://stackoverflow.com/questions/44875451

Declaring an array at a specific memory address in MIPS

旧巷老猫 提交于 2019-12-02 15:12:19
问题 How can I declare an array at memory location 100(Decimal) in a MIPS program? 回答1: The spim simulator supports the optional data directive argument as detailed here. .data <addr> The following data items should be stored in the data segment. If the optional argument addr is present, the items are stored beginning at address addr . Therefore, using spim , you can store any data at an exact address as long as it is within the range of the user data segment. In spim , the reserved range is

Declaring an array at a specific memory address in MIPS

元气小坏坏 提交于 2019-12-02 10:06:21
How can I declare an array at memory location 100(Decimal) in a MIPS program? The spim simulator supports the optional data directive argument as detailed here . .data <addr> The following data items should be stored in the data segment. If the optional argument addr is present, the items are stored beginning at address addr . Therefore, using spim , you can store any data at an exact address as long as it is within the range of the user data segment. In spim , the reserved range is 0x10000000 - 0x10040000 . So, for example, if you wanted to store an array at address 0x10000030 you would write

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

Getting the error: “Instruction references undefined symbol … main” in QTSpim

删除回忆录丶 提交于 2019-11-27 16:29:36
I'm trying to compute (a * c) - (b / d), and so far my assembly code is: .data A: .word 5 B: .word 6 C: .word 3 D: .word 2 .text lw $t0, A lw $t1, C mul $t0, $t0, $t1 lw $t1, B lw $t2, D div $t1, $t1, $t2 sub $t0, $t0, $t1 li $v0, 1 move $a0, $t0 syscall li $v0, 10 syscall But when I run it, I get the error. I am new to QTSpim and assembly so I would appreciate some help if possible. Thank you! edit: the exact error is: "Instruction references undefined symbol at 0x00400014 [0x00400014] 0x0c000000 jal 0x0000000 [main] ;188: jal main" The default startup code expects your program to have a