Skip to content
hugodecasta edited this page Sep 30, 2016 · 7 revisions

Here is our Assembly code

The assembly code described bellow is understood by the Compiler class on the app (blockapptest.GameManagement) The arduino knows how to interprete the hex byte code generated by this compiler


Input types instruction

instruction hex value use meaning
n 0x11 n 1000 decimal 1000
r 0x12 r 0 value stored on registry 0
p 0x13 p n 6 analog value on pin at adress [decimal 6]

Value Attribution instructions

instruction hex value use meaning
reg 0x11 reg 0 n 5 set registry 0 to decimal 5
pin 0x12 pin n 6 n 255 set value decimal 255 on pin 6
srv 0x13 srv n 3 n 90 rotate servo on pin 3 at 90°
ton 0x14 ton n 5 n 396 emit tone at frequency 396Hz on buzzer at pin 5

Program navigation instructions

instruction hex value use meaning
call 0x31 call my_procedure execute procedure started on the ":my_procedure:" label
jmp 0x32 jmp my_label jmp to adress on the ":my_label:" label
ret 0x33 ret return from current procedure to caller
wat 0x34 wat n 1000 wait 1000 milliseconds

Registry manupulation instructions

instruction hex value use meaning
add 0x41 add 0 n 32 add 32 to registry 0
sub 0x42 sub 0 n 32 substract 32 to to registry 0
mul 0x43 mul 0 n 100 multiply registry 0 by 100
div 0x44 div 0 n 2 divide registry 0 by 100

Comparisson instructions

instruction hex value use meaning
cmp 0x21 cmp r 0 n 512 compare value of registry 0 and decimal 512 (compare a et b)
ce 0x22 ce my_procedure call "my_procedure" if compare result was (a = b)
cn 0x23 cn my_procedure call "my_procedure" if compare result was (a != b)
cl 0x24 cl my_procedure call "my_procedure" if compare result was (a < b)
cg 0x25 cg my_procedure call "my_procedure" if compare result was (a > b)
cle 0x26 cle my_procedure call "my_procedure" if compare result was (a <= b)
cge 0x27 cge my_procedure jump at "my_procedure" if compare result was (a >= b)
je 0x28 je my_label jump at "my_label" if compare result was (a = b)
jn 0x29 jn my_label jump at "my_label" if compare result was (a != b)
jl 0x2A jl my_label jump at "my_label" if compare result was (a < b)
jg 0x2B jg my_label jump at "my_label" if compare result was (a > b)
jle 0x2V jle my_label jump at "my_label" if compare result was (a <= b)
jge 0x2D jge my_label jump at "my_label" if compare result was (a >= b)

Special instructions

instruction hex value use meaning
exit 0x00 exit uninterpreted value

Exemples

blink led on pin 6 indefinitly

:loop:
pin n 6 n 255
wat n 1000
pin n 6 n 0
wat n 1000
jmp loop

emit sound on buzzer at pin 3 depending on input at pin 5

:loop:
ton n 3 p n 5
jmp loop

light up led on pin 6 if input at pin 5 is > than 512

jmp loop

:light_on:
pin n 6 n 255
ret

:light_off:
pin n 6 n 255
ret

:loop:
cmp p n 5 n 512
cg light_on
cle light_off
jmp loop

fade led on pin 6 from 0 to 255 (for r0 = 0..255 step 1)

reg 0 n 0

:start_for:
cmp r 0 n 255
jge end
pin n 6 r 0
add 0 n 1
jmp start_for

:end:
exit