Created
March 21, 2012 08:51
-
-
Save tungd/2145675 to your computer and use it in GitHub Desktop.
Functions I used to learn Assembly language on MIPS Architecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Author: Tung Dao <[email protected]> | |
" Usage: compile .c file, load generated .s file in vim, | |
" source this script and execute the function. | |
" Requires xgcc executable which comes with MipsIT | |
" Ex: xgcc -O3 -S -c foo.c | |
" vim foo.s | |
" In vim: | |
" so ~/Desktop/mips_learn.vim | |
" call ToMIPS() | |
" Turns the numbered register to named one, compile with: | |
" xgcc -O3 -S -c foo.c | |
function! ToMIPS() | |
let s:saved_gd = &gd | |
set nogdefault | |
silent! %s/\$0/zero/g | |
silent! %s/\$10/t2/g | |
silent! %s/\$11/t3/g | |
silent! %s/\$12/t4/g | |
silent! %s/\$13/t5/g | |
silent! %s/\$14/t6/g | |
silent! %s/\$15/t7/g | |
silent! %s/\$16/s0/g | |
silent! %s/\$17/s1/g | |
silent! %s/\$18/s2/g | |
silent! %s/\$19/s3/g | |
silent! %s/\$20/s4/g | |
silent! %s/\$21/s5/g | |
silent! %s/\$22/s6/g | |
silent! %s/\$23/s7/g | |
silent! %s/\$24/t8/g | |
silent! %s/\$25/t9/g | |
silent! %s/\$26/k0/g | |
silent! %s/\$27/k1/g | |
silent! %s/\$28/gp/g | |
silent! %s/\$29/sp/g | |
silent! %s/\$30/fp/g | |
silent! %s/\$31/ra/g | |
silent! %s/\$1/at/g | |
silent! %s/\$2/v0/g | |
silent! %s/\$3/v1/g | |
silent! %s/\$4/a0/g | |
silent! %s/\$5/a1/g | |
silent! %s/\$6/a2/g | |
silent! %s/\$7/a3/g | |
silent! %s/\$8/t0/g | |
silent! %s/\$9/t1/g | |
silent! %s/\$\ze//g | |
let &gd = s:saved_gd | |
endfunction! | |
" Format the output to readable Assembly code with inline C comment, compile with: | |
" xgcc -c -g -O3 -Wa,-adhln,-L foo.c | |
function! FormatMIPS() | |
silent! %s/^.\{19\}// | |
silent! g/\.loc/d | |
silent! call ToMIPS() | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment