2

We are using a real MIPS microprocessor for our computer architecture class.
We ssh into our linux server at school, and then run our MIPS assembly from there.

I have been trying to run :

# Hello World!
        .data

## String to be printed:
out_string:     .asciiz    "\nHello, World!\n"

        .text
        .global main
main:

        li $v0, 4
        la $a0, out_string
        syscall

        li $v0, 10
        syscall

I run gcc "file".s and it compiles.
However, the string I am expecting to print to the screen doesn't get printed.
My question is am I able to use syscall with the system we have, or is that only going to work with emulators ?

Thanks

boraseoksoon
  • 2,164
  • 1
  • 20
  • 25
MuffinMan1042
  • 75
  • 1
  • 11
  • 4
    Your code looks a lot like the stuff one runs on SPIM. You're running on a **real** MIPS processor, running the Linux kernel. The Linux kernel has its own, very well-defined syscall interface (in which registers to put which values at the moment of a syscall). The syscalls you're interested are `write(int fd, void* buf, size_t len)` and `exit(int code)`. [Here's an example of them being used.](https://www.linux-mips.org/wiki/Syscall#Example) – Iwillnotexist Idonotexist Oct 15 '16 at 04:53
  • 2
    Recently I was answering to the same issue: http://stackoverflow.com/a/40040841/4271923 – Ped7g Oct 15 '16 at 14:08
  • Ped7g's answer on the linked duplicate explains the difference between Linux and MARS syscalls. – Peter Cordes Oct 15 '16 at 17:27
  • @IwillnotexistIdonotexist, I have read the page but am struggling trying to understand how to implement the calls. If it's not too much trouble, can you just give me a simple example of how to read/print? – MuffinMan1042 Oct 15 '16 at 19:30
  • Broadly speaking, your application is powerless to do anything significant on its own. It must _request_ that actions such as I/O be done by the Linux kernel on its behalf, and those _requests_ (also called **system calls**) are subject to permission checks. Between the kernel and your application exists a "contract" for how such requests are to be made and replied to: The _system call interface_. It specifies that your application shall indicate precisely its request by putting specific values in specific registers, and the kernel will likewise place its reply in a specific register. – Iwillnotexist Idonotexist Oct 15 '16 at 20:25
  • Now, MIPS has a long history of incompatible "contracts" between the kernel and userspace. The more famous ones are called O32, N32 and N64. I don't know enough to tell you which one your system supports. The link I put above, if you scroll up, attempts to describe all 3. – Iwillnotexist Idonotexist Oct 15 '16 at 20:41
  • In essence, for O32 interface: reading/writing it involves putting the syscall number in `v0` (4003=read, 4004=write), the integer file descriptor (0=stdin, 1=stdout, 2=stderr, anything else is usually something returned by `open()`) in `a0`, the pointer to the buffer to read/write to/from in `a1` and the number of bytes of the buffer in `a2`, then execute `syscall`. The kernel replaces `v0` with the number of bytes read/written when it gives back control. The buffer could be somewhere on the stack, for instance. To `exit()` put `4001` in `v0` and the exit code in `a0`, then execute `syscall`. – Iwillnotexist Idonotexist Oct 15 '16 at 20:52

0 Answers0