1

Here is code:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    puts("Hello World!"); /* prints Hello World! */
    return EXIT_SUCCESS;
}

When I use tool in to convert C to MIPS, I had a MIPS code: .text

    .abicalls
    .option pic0
    .section    .mdebug.abi32,"",@progbits
    .nan    legacy
    .set    mips32r2
    .file   "/tmp/webcompile/_26392_0.c"
    .text
    .globl  main
    .align  2
    .type   main,@function
    .set    nomicromips
    .set    nomips16
    .set    mips32r2
    .ent    main
main:
    .frame  $sp,24,$ra
    .mask   0x80000000,-4
    .fmask  0x00000000,0
    .set    noreorder
    .set    nomacro
    .set    noat
    addiu   $sp, $sp, -24
    sw  $ra, 20($sp)
    lui $1, %hi($.str)
    jal puts
    addiu   $4, $1, %lo($.str)
    lw  $ra, 20($sp)
    addiu   $2, $zero, 0
    jr  $ra
    addiu   $sp, $sp, 24
    .set    at
    .set    macro
    .set    reorder
    .end    main
$func_end0:
    .size   main, ($func_end0)-main

    .type   $.str,@object
    .section    .rodata.str1.1,"aMS",@progbits,1
$.str:
    .asciz  "Hello World!"
    .size   $.str, 13


    .ident  "ecc 0.1.13 based on clang version 3.7.0 (trunk) (based on LLVM 3.7.0svn)"
    .section    ".note.GNU-stack","",@progbits
    .text

After I copy all code into MARS to build, It,s error.

    Error in D:\Desktop old\mips1.asm line 4 column 28:     .section    .mdebug.abi32,"",@progbits
    Error in D:\Desktop old\mips1.asm line 47 column 32:    .section    ".note.GNU-stack","",@progbits

What I need do? Why MIPS code not run in MARS?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
DustinPham
  • 91
  • 1
  • 6
  • The generated assembly code is meant to be assembled with the GNU assembler. MARS doesn't use most of the directives found in that code, and it has its own way of doing console I/O so the `jal puts` isn't going to work. I also don't think that it supports the `%hi`/`%lo` macros. But with such a trivial C code, why don't you just translate it yourself instead of trying to use a compiler? – Michael Nov 23 '15 at 06:22
  • I can translate this program. But my program is very complex. Not "hello word". The requirement use tool or ubuntu to covert C to MIPS and can run on MARS :( – DustinPham Nov 23 '15 at 06:46
  • 1
    Well, then you probably have a fair amount of work ahead of you editing the generated assembly code. Consult the GNU assembler manual to see what the directives do. – Michael Nov 23 '15 at 07:20
  • Related: [Tweak mips-gcc output to work with MARS](https://stackoverflow.com/q/13052444) – Peter Cordes Mar 31 '22 at 21:04

0 Answers0