When v2.0.0 got released, a 32x8 text display and a bunch of other features were added, which allows us to create a Hello World program.
First of all, Asembsim does not come with premade functions like a print function. So in order to print something on the screen, you must make your own print function.
Print function algorithm
The print algorithm we are writing would require a pointer to the message. We could do that by storing the two pointer values of the label into r0 r1 as shown below.
imd Message:0 r0 imd Message:1 r1
Then create label somewhere that labels a DB pseudo instruction as shown below.
.Message db "Hello World!"
Now that we have setup the message, we also need to use the IMD instruction to store the length of the message into r2 and the position on screen to r3.
We begin by creating the print function, by adding a label ".print" then we use the IMD instruction to set values in r4 and r5 by zeroing out r4 as it would later contain the letter to print, and to set the value of r5 to be the video memory block (0xF).
We add a ".print_loop" label since we are about to loop through all the message characters. So now for every iteration in the loop, we would use the LDR instruction to load the character from the message we set earlier, and store it inside the video memory block, then we increment our pointers and jump back to print_loop as long as r0 is less than r2, in which r2 is the message length. One loop ends, you use the RET instruction. The print function is as shown below.
.print ; Print function; Requires 4 parameters placed in r0 to r3
imd 0 r4 ; holds character to print
imd 0xF r5 ; video memory block pointer
add r0 r2 r2 ; Tells which part of the message to stop
.print_loop
ldr r0 r1 r4 ; Load a letter into r4
str r4 r3 r5 ; Store letter in video memory
inc r3 ; Increment iteration
inc r0 ; Increment message pointer
cmp r0 r2 ; Compares between r0 and r2
jmp_ls print_loop ; loop back if r0 < r2
retThe full Hello World program code
imd Message:0 r0 ; 1st pointer to message
imd Message:1 r1 ; 2nd pointer to message
imd 12 r2 ; message length
imd 0 r3 ; Where it should be displayed on screen
call print ; Runs print function
hlt ; Stop the program
.print ; Print function; Requires 4 parameters placed in r0 to r3
imd 0 r4 ; holds character to print
imd 0xF r5 ; video memory block pointer
add r0 r2 r2 ; Tells which part of the message to stop
.print_loop
ldr r0 r1 r4 ; Load a letter into r4
str r4 r3 r5 ; Store letter in video memory
inc r3 ; Increment iteration
inc r0 ; Increment message pointer
cmp r0 r2 ; Compares between r0 and r2
jmp_ls print_loop ; loop back if r0 < r2
ret
.Message ; Contains a message stored directly in code
db "Hello World!"