Archive for the 'MIPS' Category

MIPS and .vimrc Fun, Part One

September 23rd, 2006 by peasleer

I’m in a course that requires us to write programs in MIPS assembly. I’m really enjoying the course, but even this early on I’m seeing repetition regardless of the lab or project. I believe my editor is here to make my life as a coder easier, so I’ve thrown together a couple functions for my .vimrc to handle some common tasks. The first is mapping numerical syscall values to constants so I don’t have to look at them while coding. The first version is for all syscalls, and the second is for syscalls I commonly use.

In your .vimrc:



" Makes constants for syscalls
command AllSyscalls call AllSyscallsAsConstants()
function AllSyscallsAsConstants()
    call append(line("."), "EXIT = 10")
    call append(line("."), "SBRK = 9")
    call append(line("."), "READ_STRING = 8")
    call append(line("."), "READ_DOUBLE = 7")
    call append(line("."), "READ_FLOAT = 6")
    call append(line("."), "READ_INT = 5")
    call append(line("."), "PRINT_STRING = 4")
    call append(line("."), "PRINT_DOUBLE = 3")
    call append(line("."), "PRINT_FLOAT = 2")
    call append(line("."), "PRINT_INT = 1")
endfunction

command CommonSyscalls call CommonSyscallsAsConstants()
function CommonSyscallsAsConstants()
    call append(line("."), "EXIT = 10")
    call append(line("."), "SBRK = 9")
    call append(line("."), "READ_STRING = 8")
    call append(line("."), "READ_INT = 5")
    call append(line("."), "PRINT_STRING = 4")
    call append(line("."), "PRINT_INT = 1")
endfunction


To use them, after saving your newly updated .vimrc, just type :AllSyscalls or :CommonSyscalls to have the constants created on the line your cursor is currently at. And despite how it looks, the function will create them in numerical ascending order.