FAQ Database Discussion Community


GCC compile and link raw output

gcc,assembly,mips
I am trying to get the raw instruction code output for a simple C program with function calls. I have already searched on here and Google for the answer but can only find answers that are correct for single functions (no function calls). A trivial example: int main(){ return addition(5,...

Cross compiling driver for mips

driver,mips,cross-compiling
I am trying to compile a simple driver example for a mips device. The driver is really just a test: #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); int ath_pci_init(void) { printk(KERN_ALERT "alive and hacked\n"); return 0; } void ath_pci_exit(void) { printk(KERN_ALERT "dead and hacked\n"); } module_init (ath_pci_init); module_exit (ath_pci_exit); And compiles...

How can you ask for user input when also using a text file in unix shell in c++?

c++,file,shell,unix,mips
I run my code using a.out < file.txt and I read all of the file when I try to use cin >> variable to ask the user for input it does nothing.

Calculate Virtual Memory Page Faults Number

caching,memory,mips,virtual-memory
I have trouble with calculating number of page faults. I have a question that is: Consider the two-dimensional array D defined as follows: int D (128, 128); # each element is one word (I think it means 32 bit) Assume that the OS only makes one 1024-byte page frame available...

MIPS instructions to set a register to 1

mips
This is a question that has appeared in a few past papers but I cannot find anything about it on the internet. What six single instruction MIPS can set $v1 to hold the decimal value of 1?...

Jump to Address after Branching in For Loop in MIPS

c,byte,branch,mips,bit
I am trying to code a program that checks if the 16 bits in an integer is a one or zero. I chose to implement this by shifting right one bit 15 times and checking if the first bit in each shift is a zero or non zero. Then, if...

read in MIPS file opened in C

c,mips,readfile
i have a c function where i open and close a file. But i want to replace the fgets function for a custom readFile function implemented in MIPS. According to: When reading file in MIPS, it reads last line twice and http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html i need to pass the syscall the code...

Assign value 0xB33C to register $t0

assembly,mips
Assign value 0xB33C to register $t0. The answer to this is: ori $t0, $zero, 0xB33C but, I'm confused why. I thought the answer would be addi $t0, $t0, 0xB33C. Can someone explain this to me please? I'm not sure how the ori instruction works....

Android live build jars: arm64, armabi, mips, mips64, x86

android,jar,x86,mips
I am using an external library that uses a native lib. In my APK (and inside this external library) separate jars are packaged for: arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64 There jars are quite large. I want to remove some of them. Are there any LIVE devices using x86?...

Changing C to MIPS and bitwise or [closed]

c,mips
b = 25 | a; Assume that a corresponds to register $t0 and b corresponds to register $t1.? Can anyone explain how to approach this and can give me the final answer so I can compare with mine after I do it?

MIPS sw dependency

dependencies,mips
I have question about MIPS code and dependency. If i have following MIPS code. How it works without any forwarding unit? How many stalls needed to be insert? 7 ADD $t5, $t4, $t5 8 SUB $t5, $t5, $t3 9 SW $t5, 24($t0) In my opinion: line 7-8 WAW, RAW dependency...

Identical (almost) ELF headers but executables won't run on each other's system

c,linux,embedded,mips
I'm trying to compile a couple of programs for a little embedded device I own. It's a Little-endian MIPS (mipsel) processor. I retrieved this executable from it via telnet and the builtin ftp client: [email protected]:/home/user/wansview/devel# readelf -h unzip1 ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00...

MIPS Dynamic Array Error

arrays,dynamic,mips,allocation,qtspim
I'm trying to allocate a dynamic array and get it to accept input from the console, but once I start entering a few of the numbers into the array it says there is an Exception 7 error. (Bad Data Address) Here is the code I use before running the subprogram...

MIPS assembly, stacks and basic addition

assembly,mips
I am currently working on an assignment for class that requires us to accept user input values for two variables (a and b) and solve the equation [a - ab + 8a - 10b + 19] while using only the stack and registers $t0 and $t1. I understand what I...

About the latches generated by “case” syntax

mips,verilog,system-verilog
I understand when using case syntax in systemverilog, we need to fully describe all combinations or add a default to avoid latches. Here is my example code, no latches are generated: module test( input logic[2:0] op, output logic a,b,c ); always_comb begin case(op) 0: {a,b,c} = {1'b1,1'b1,1'b0}; 1: {a,b,c} =...

Only Swapping Once?

assembly,mips
I'm trying to implement Bubblesort in MIPs. I'm so close to figuring it out, unfortunately my code only seems to swap one element in the array. My thoughts was that swap is not linked back to the loop procedures, so only one swap is performed when the subroutine to print...

MIPS Runtime Error with “Cannot write directly to text segment”?

assembly,runtime-error,mips
I was trying to store something into a memory address and came across this error. This is a sample of what I'm doing: sll $11, $10, 2 #register $10 for this loop contain 1 mflo $9 # answer from previous calculations # which is placed right above the sll instruction...

Undefined reference to printf when using GCC cross compiler

c,gcc,mips,cross-compiling,undefined-reference
I'm trying to get the following simple 'Hello World' program to compile using a cross compiler (GCC 4.9.2) targeting mips: #include <stdio.h> int main() { int x = 5; printf("x = %d\n", x); } The x variable is there to stop GCC changing printf to puts, which it seems to...

ELF loading on MIPS, malloc issue

mips,elf,libc,musl
I'm loading a plain statically linked ELF binary in MIPS (32-bit). After mapping the loadable segments, this is how I set up the stack before jumping into my target ELF's CRT's _start function: __asm__(" \ addi $2, %[envN], 0 ;\ .env_loop: \ addi $2, $2, -4 ;\ lw $3, 0($2)...

Has anyone created a MIPS syntax highlighter for Ace Editor?

user-interface,mips,ace-editor
I'm trying to create a MIPS syntax highlighting. There's a copy of the .tmLanguage file to be used for TextMate markup and the like on GitHub here. I'm also aware that Ace Editor's ability to perform a conversion on this file. The setup did not seem nontrivial, and I ran...

Save registers on a stack in a procedure call in Assembly

assembly,stack,mips
I'm taking an intro course on Assembly and I encountered the following code. I'm not sure how stacks work here. This is the C code that's supposed to be translated into Assembly: (Sorry I forgot to mention we are using MIPS) int leaf_example (int g, h, i, j) { int...

Figuring out how to set up memory for MIPS simulator

c,mips
I'm writing a MIPS simulator in C++. It takes in a text file in hex, and needs to output the register contents and the decoded instruction after every instruction. So I convert the hex file to binary to grab the opcodes, rs, rt, rd, funct, and sham field so I...

Address Out of range mips

assembly,mips
Hello i am trying to implement the mccarthy 91 function in assembly code. When i run my code it assembles with no errors but when i enter a value for n the program gets runtime exception address out of range. I've looked over my code and i cant find out...

Range of Addresses for a Conditional Branch Instruction in MIPS

assembly,mips
What is the range of addresses for a conditional branch instruction in MIPS with respect to X, where X contains the address of the branch instruction? Assume the current PC value is 0x10000000. What is the range of addresses for jump (j) and the jump and link (jal) in- structions...

MIPS Why I can't print the selected array position?

arrays,string,printing,mips
Whit this code the simulator says: memory addres out of bound" and print(null) t0 is the index, initially set to 0, it's portion of a cicle. la $t1, nome #array address mul $t2, $t0, 4 # t2=index*4 add $t3, $t2, $t1 lw $a0, nome($t2) li $v0, 4 syscall That's the...

MIPS, why this branch doesn't work?

arrays,branch,mips
I have to do a bne taking one argument from an array declared pp: .space 40, in that array i put integer, 0 or 1, it's a flag. But whatever I do, the bnenever work! How I have to pass the argument?? li $s5, 0 li $t1, 10 la $s0,...

Organizing pipeline in MIPS

mips,pipeline
I'm unsure about how the following properties affect pipeline execution for a 5 stage MIPS design (IF, ID, EX, MEM, WB). I just need some clearing up. only 1 memory port no data fowarding. Branch stalls until end of * stage Does the 1 memory port mean we cannot fetch...

How to Shorten MIPS Print Statements

assembly,mips
I've been working on a program that calculates a GCD and LCM and then prints them out but have noticed I spend half of my code just printing stuff. I've had it organized by saving the text blocks as: Ask_Input_1: .asciiz "Enter first integer n1: " Ask_Input_2: .asciiz "Enter second...

How do I force GAS to generate output identical to input?

c,optimization,mips,gas
I want to write code that has a public C interface, but is otherwise implemented entirely in MIPS, mainly as a learning exercise. However, I'm stuck fighting GAS because it seems to assume it knows better than I do. To illustrate, let's say I want to implement the following in...

MIPS .data Segment to Machine Code

assembly,mips,machine-code
I have to convert the following code from the .data segment into machine code, but I am unsure as to how this is done. value: .word -39 I understand the process for .asciiz variables, but I cannot find any information on .word variables to machine code. Also, does the processor...

mips converting to assembly

architecture,mips
I was working with Writing MIPS assembly for the following statement: f = a - 20 + b + c - d using the following registers $1 a $2 b $3 c $4 d $5 f $6 g $7 i $8 j $9 A 10$ D my answer is this:...

Palindrome Checker in Mips

mips
I'm taking a computer organization class that teaches the low level functions of computers through MIPS Assembly. One problem on a homework is a palindrome checker. Here it is: Write a MIPS function (called “palindrome”) that returns 1 if the input string is a palindrome and returns 0 otherwise. The...

Program defining if an input integer is divided by 2

mips
I am trying to make a program on QtSpim that constantly takes new integers as input (through the console) and then prints them on the console only when they are even numbers. I set the input 5 as the exit case. The program compiles as it should and when I...

How to represent mips instruction as it's hex representation

assembly,mips
I'm given a MIPS instruction: top: lw $t1, ($t0) beq $s0, $0, end jal func add $s0, $s0, $t0 addi $s0, $s0, -1 j top bne $s0, $0, top end: func: sll $v0, $t1, 4 jr $ra and am told to convert each line to the "instruction in hex." What...

Pipelined MIPS delayed branching example

assembly,mips,pipeline
I'm given this MIPS pseudo-assembly code: add r7,r8,r9 beq r1,r2,40 --- lw r4,O(r1) ' sub r5,r1,r4 ' and r6,r4,r2 ' <--------------- ' or r4,r2,r3 I am supposed to assume that there are no structural hazards and that delayed branching is used. The questions are: how will the instructions be executed...

MIPS “spim: (parser) syntax error”

mips,qtspim
I'm building a program on MIPS for checking if the column of a matrix is ordered in a increasing way, in a decreasing way, if all it's numbers are equal or if it's disordered. Here's the code: # #include <iostream> # int m; int n; # int M[m][n]; # #...

code is not reprinting board after initial print.. 2x2 Dots and Boxes game

printing,mips
The below code is a one player 2x2 Dots and Boxes Game. It prints the board at first and waits for the user input. After that, it simply does not print the board but successfully asks the question. Any insight? .data board: .ascii "\n\n . . . . 0 ....

Loading and storing bytes in MIPS

mips
I'm studying for an exam tomorrow and I'm quit confused on the loading/storing bytes topic. I have this example: http://i.stack.imgur.com/kngyn.png I don't understand how he got the answers in red at all. Could someone help explain this to me? Thanks....

MIPS: Does a load word create a data hazard if an instruction loads from the same register?

mips,instructions
Does a load word create a data hazard if a subsequent instruction loads from the same register? I have lw $t0 0($t1) addi $s0, $t1, 4 Would this create a data hazard, since you need what is stored in the register for both operations? What if the instructions are reversed...

Encode in machine code an Assembly MIPS instruction

assembly,mips
I need to encode the following beq instruction: ... start: addu $8, $9, $10 addiu $8, $8, 0x00FF7A01 beq $8, $0, start ... I know that it is a J format instruction so the division will be 6 bits to opcode and 6 to target address. beq opcode is 000100,...

MIPS - is there a way to transfer the value of the flag in coprocessor 1 to integer registers of coprocessor 0?

assembly,floating-point,comparison,mips,spim
I'm making a compiler for a school project and I am using MIPS assembly as my target code. But that's not important. I know that operations involving floating-point numbers are done in coprocessor 1 and that result of comparison instructions like c.eq.d and c.le.d are in the flag that can...

Assembly Language - Display Integer based on cases of characters

assembly,mips,mips32
so quick question. I have a program that accepts two characters (letters) from a user - all I have to do is output an integer representing a comparison of the case of these two letters. 0-3 are the possible output, and below are the examples. If the user enters two...

Using Nested For Loops and an Array in MIPS

c,arrays,assembly,mips
This is a homework assignment, I've written the whole program myself, run through it in the debugger, and everything plays out the way I mean it to EXCEPT for this line: sw $t1, counter($a3) The assignment is to convert this snippet of C code to MIPS for(i = 0; i...

Read binary file into array in MIPS

assembly,mips,file-read
I've got a file named trace.dat that contains 4 byte integers. Can anybody tell me how to open and read the file, and store each integer in an array called arr (in MIPS)? Thanks! So far I have this: li $v0, 13 la $a0, file #file contains the file name...

Pseudoinstructions with real instruction mnemonics

assembly,mips
str9 is a label for a byte allocated in a .data section, and the address of this byte is 0x1001_58e4. Determine the machine code that would be generated as a result of this pseudo instruction: lbu $t1, str9 I don't understand why this is a pseudo instruction at all and...

NetBSD kernel crash due to cache error - What is good point to start debugging?

caching,kernel,mips,interrupt,netbsd
Below is the stack trace of NetBSD 5.1 kernel crash. Basic data collected from minicore is : ------------------------------------------------------------- VALID MAGIC: 0xdfeedfee --------------------------PANIC STRING----------------------- panic string is :cache error @ EPC 0xffffffff80359a78 L1D_CACHE_ERROR_LOG 0 L1D_CACHE_INTERRUPT 0 status 0x8305, cause 0x78 Stack Trace : sys/arch/evbmips/navasota/md_dump.c:52: 803e092c : sys/arch/evbmips/rmixl/machdep.c:1247: 8032c468 : sys/kern/subr_prf.c:313: 802934ec...

storing array from user and accessing it

arrays,assembly,input,user,mips
I have to create an int array based on user input, sum the integers, and output the sum and the array itself. My code calculates the sum correctly, but I cannot output the list. It only prints out the last number and zeros and then gets stuck in an infinite...

MIPS float printing

double,mips
I wrote this code in MIPS to calculate the sum of N-numbers with double float precision. But when I print the result it prints 0.00000 althought I see that in memory it's the correct result. Anyone can help me with this? #architecture ex.2 .data first: .asciiz "Give the number of...

C to MIPS conversions

c,set,mips
int MyArray[30]; int n = 2; MyArray[0] = 1; MyArray[1] = 1; do{ MyArray[n] = MyArray[n-1] + MyArray[n-2]; n++; } while(n < 30); While I was doing this I got stuck on how i can recursively call the function without the use of return address $ra or $sp since the...

MIPS printing string

mips
So here is the practice question: Given the data segment below, write the code to print the string “Hello” .data .asciiz “A” .asciiz “Hello” .globl main main: What I wrote under main: main: lui $a0, 0x1001 addi $v0, $0, 4 syscall The output I am receiving is "A", obviously it's...

MIPS - How to store the first 256 numbers in memory

assembly,mips,spim
I have to write a program in assembly language that is to store in memory the first 256 integers from 0 to 255. Here is the code I wrote (I am a beginner with the assembly language): .data memory: .space 256 .text li $t0, 0 la $s0, memory sb $s0,...

What is the difference between the various syscalls in MIPS for random numbers?

mips
What is the difference between the various syscalls in MIPS for random numbers? Specifically, I'm looking at 41 vs 42 and 43 vs 44. Also is there any guideline as to what seed I should use or is that completely arbitrary?

How can I access the individual elements of an array in a loop?

assembly,mips
I need to print the cells of an array, I have an array which contains the word "HELLO_WORLD", I manage to print an index by its own but I can't manage to print all the cells one by one, here is the code : loop: la $t0, hexdigits # address...

Using Stack for variable allocation mips

assembly,stack,mips
I am trying to convert c functions into mips assembly code as a practice. I was trying to allocate the space on stack for local variables & function arguments. But I get alignment errors at run time. I know that the memory should be aligned with appropriate data structure (i.e....

Storing words into an array in Mars MIPS

assembly,mips,mars-simulator
I'm trying to teach myself Assembly using Mars for the MIPS architecture and am wondering how to store a series of words into an array. I know that if I have 4 words, I'd allocate 16 bytes like so: .data X: .space 16 I then have some words: .data X:...

Why load address works different on words and labels with strings?

mips
​Hi, I just had a quick question. Let's say I have 2 labels string and word with string being a label associated with a string and word being an actual word with a 32 bit integer stored in it. Now let's say I use a syscall to print string using...

MIPS Converting hex to decimal, writing to a file

assembly,mips
I've got a problem, that I can't manage with. I'm trying to convert A-F chars to its decimal equivalents by subtracting 55 from the read byte, then putting it into a buffer and finally, write to a file. When I subtract and store a byte like this: addi $t2, $t2,...