Created
January 7, 2013 18:53
-
-
Save Frdnspnzr/4477431 to your computer and use it in GitHub Desktop.
Seltsames Quine für den MIPS-Assembler MARS (Nicht so schön.)
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
.data | |
d00: .asciiz "0" | |
d01: .asciiz "1" | |
d02: .asciiz "2" | |
d03: .asciiz "3" | |
d04: .asciiz "4" | |
d05: .asciiz "5" | |
d06: .asciiz "6" | |
d07: .asciiz "7" | |
d08: .asciiz "8" | |
d09: .asciiz "9" | |
d10: .asciiz "A" | |
d11: .asciiz "B" | |
d12: .asciiz "C" | |
d13: .asciiz "D" | |
d14: .asciiz "E" | |
d15: .asciiz "F" | |
error: .asciiz "Error" | |
blank: .asciiz " " | |
break: .asciiz "/n" | |
.text | |
.globl main | |
main: | |
#Adresse des Programms laden | |
la $s0,main | |
#Durchlauf initialisieren | |
li $s1,1 | |
loop: | |
#Wenn wir bei quit ankommen Schleife verlassen | |
la $t0,quit | |
beq $s0,$t0, exit | |
#Was an Speicheradresse $s0 steht ist Parameter für binhex | |
lw $a0,($s0) | |
jal binhex | |
#Ausgabe des Ergebnis von binhex ($v0) | |
#syscall code 4 ist print string | |
add $a0,$zero,$v0 | |
li $v0,4 | |
syscall | |
#Wenn der aktuelle Durchlauf $s1 durch 2 teilbar ist blank ausgeben | |
div $t0,$s1,2 | |
#Nach der Division steht in HI der Rest der Division | |
mfhi $t0 | |
#Wenn der Rest = 0 ist die Zahl durch 2 teilbar | |
bne $t0,0,not_div_2 | |
jal print_blank | |
not_div_2: | |
#Wenn der aktuelle Durchlauf $s1 durch 32 teilbar ist blank ausgeben | |
#(Aequivalent Implementierung oben) | |
div $t0,$s1,32 | |
mfhi $t0 | |
bne, $t0,0,not_div_32 | |
jal print_break | |
not_div_32: | |
#Adresse um eins erhoehen (naechster Block) | |
addi $s0,$s0,1 | |
#Nummer des Durchlaufs erh?hen | |
addi $s1,$s1,1 | |
j loop | |
exit: | |
j quit | |
print_blank: | |
la $a0, blank | |
li $v0, 4 | |
syscall | |
jr $ra | |
print_break: | |
la $a0, break | |
li $v0, 4 | |
syscall | |
jr $ra | |
#Ja, die Implementierung von binhex ist nich sexy, aber dafür einfach | |
#Parameter $a0 wird auf die letzten vier Bit reduziert und dann eine simple | |
#Falluntersheidung vorgenommen | |
binhex: | |
#Parameter mit 0000 0000 0000 1111 verunden | |
andi $t0, $a0, 15 | |
#In $t0 steht jetzt eine Zahl <= 16 mit dem Wert der vier niedrigwertigsten Bits | |
#Wenn t0 = 0 springe zu l00 | |
li $t1, 0 | |
beq $t1,$t0,l00 | |
#Wenn t0 = 0 springe zu l01 | |
li $t1, 1 | |
beq $t1,$t0,l01 | |
#Usw. | |
li $t1, 2 | |
beq $t1,$t0,l02 | |
li $t1, 3 | |
beq $t1,$t0,l03 | |
li $t1, 4 | |
beq $t1,$t0,l04 | |
li $t1, 5 | |
beq $t1,$t0,l05 | |
li $t1, 6 | |
beq $t1,$t0,l06 | |
li $t1, 7 | |
beq $t1,$t0,l07 | |
li $t1, 8 | |
beq $t1,$t0,l08 | |
li $t1, 9 | |
beq $t1,$t0,l09 | |
li $t1, 10 | |
beq $t1,$t0,l10 | |
li $t1, 11 | |
beq $t1,$t0,l11 | |
li $t1, 12 | |
beq $t1,$t0,l12 | |
li $t1, 13 | |
beq $t1,$t0,l13 | |
li $t1, 14 | |
beq $t1,$t0,l14 | |
li $t1, 15 | |
beq $t1,$t0,l15 | |
#Hier sollten wir nie ankommen, eigentlich | |
la $v0,error | |
j exit_binhex | |
l00: | |
#Adresse von "00" als Rückgabewert setzen und rausspringen | |
la $v0,d00 | |
j exit_binhex | |
l01: | |
#Adresse von "01" als Rückgabewert setzen und rausspringen | |
la $v0,d01 | |
j exit_binhex | |
l02: | |
#usw. | |
la $v0,d02 | |
j exit_binhex | |
l03: | |
la $v0,d03 | |
j exit_binhex | |
l04: | |
la $v0,d04 | |
j exit_binhex | |
l05: | |
la $v0,d05 | |
j exit_binhex | |
l06: | |
la $v0,d06 | |
j exit_binhex | |
l07: | |
la $v0,d07 | |
j exit_binhex | |
l08: | |
la $v0,d08 | |
j exit_binhex | |
l09: | |
la $v0,d09 | |
j exit_binhex | |
l10: | |
la $v0,d10 | |
j exit_binhex | |
l11: | |
la $v0,d11 | |
j exit_binhex | |
l12: | |
la $v0,d12 | |
j exit_binhex | |
l13: | |
la $v0,d13 | |
j exit_binhex | |
l14: | |
la $v0,d14 | |
j exit_binhex | |
l15: | |
la $v0,d15 | |
j exit_binhex | |
exit_binhex: | |
jr $ra | |
quit: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment