Examples for Xmas

Here you can find some examples for Xmas, to try its cut and paste into a file, load it into Xmas and press Run. These files and much others are included into every Xmas distribution.

Name & source code Description
2^3.xmas
.Pc 0
.text
addi $1 $0 0002
addi $2 $0 0003
addi $3 $0 1
mult $1 $3
mfhi $3
addi $2 $2 -1
bne $2 $0 -3
halt
calculate 23 as a sequence of multiply, where $2 is the base and $3 is the exponent
9mod5.xmas
.Pc 0
.text
addi $1 $0 9
addi $2 $0 5
addi $3 $1 0
sub $3 $2 $3
slt $4 $3 $2
beq $0 $4 -2
halt
calculate 9 mod 5 as continous substraction of 5 by 9, where $1 is 9 and $2 is 5
countdown.xmas
.Pc 0
.text
addi $1 $0 0
addi $2 $0 ff
addi $2 $2 1
addi $2 $2 -1
addi $1 $1 1
bne $0 $2 -2
halt
load the counter $2 with ff and countdown to zero while $1 grow up to ff
div.xmas
.Pc 0
.text
addi $1 $0 8
addi $2 $0 3
div $1 $2
mflo $0
halt
show how work the div istruction, the result is stored into $lo register
infinity+all.xmas
.Pc 0
.text
addi $8 $0 b
addi $1 $0 1

add $2 $2 $1
addi $4 $4 0
and $4 $2 $3
bne $2 $2 2
div $1 $1
lui $4 ffff
lw $4 $0 20
j a
jr $8
mfhi $3
mflo $3
mthi $3
mtlo $3
mult $1 $1
nop
or $3 $2 $3
ori $3 $2 0
sll $3 $3 3
sllv $3 $3 $7
slt $4 $1 $2
slti $2 $3 0
srl $3 $3 3
srlv $3 $3 $7
sub $4 $2 $2
sw $2 $0 20
xor $3 $4 $5
xori $3 $4 7
beq $2 $2 -1b
halt
this is an infinite loop to test the Time Limit feature and to test the Xmas executor with all istructions
NOTE: active the Time Limit before run this code!!! otherwise it NOT terminate!!!
lui.xmas
.Pc 0
.text
lui $1 f
addi $1 $1 000f
halt
show how work the lui istruction (lui = load upper immediate), load the 16 bit high of a word with the value 0xf
lw.xmas
.Pc 0
.text
addi $1 $0 ff
sw $1 $0 f
lw $0 $0 f
halt
show how work the lw istruction (lw = load word), load a word from memory to register
sample.xmas
.Pc 0
.text
lui $1 000f
sw $1 $0 00ff
addi $2 $0 000f
sw $2 $0 00fe
add $3 $2 $1
sw $3 $0 00fd
halt
an example of loadable file

[UP]Xmas DOCUMENTATION PAGE 21:19:11
Tue 05-Dec-2000
http://punto.dov.it/~paolo/Xmas/docs/examples.php3