How to truncate the leading zeros when using syscall to print binary/hex in MIPS

40 Views Asked by At

I have this code that converts decimal to binary using syscall :

.text 

main:

    li $v0, 35
    li $a0, 3
    syscall

which convert 3 to a binary. This is the output :

00000000000000000000000000000011

And this is to print Hex :

0x00000003

But I want to truncate the leading zeros in binary and hex. Any idea how? I also want to remove the 'x' from the hex

1

There are 1 best solutions below

1
Erik Eidt On

In short, there's no way to do this kind of formatting using MARS/QtSpim syscalls.

I'm surprised we don't have a standard answer for this!

The MARS environment appears to be designed to allow simple programming easily, but is far from complete and virtually uncustomizable, so you get to write code for doing things like that.

In another environment, we could imaging printing to a string (or to a file) for post processing, like removing leading zeros, but not here. Those print functions only go to the console, so there's no way to capture their output and re-process.

In another environment, we would have general purpose formatting capabilities, like printf, but again, not here. These simulators have no standard libraries, either, so the syscalls are all we get.

And there's no reason for these simulators to do more as they target teaching.