Files
lang-assm/examples/strlen.asm
T

37 lines
987 B
NASM

namespace string 67; my string namespace here
word FRAMEBUFFER 0x00200500
asciiz Msg "Hello World!"
; fn effectively is an "Append to Namespace" command, ie string + "." + _start
fn _start:
mov FRAMEBUFFER, r32 ; imm, r
mov msg, r1 ; imm, r
call strlen ; result into r2
mov 0, r4 ; counter
loop:
mov byte [r1], r3 ; read char into r3
cmp r3, 0 ; NUL byte?
je end
mov byte r3, [r32] ; Write char to frame buffer
inc r32 ; Next space in framebuffer
inc r4 ; inc counter
inc r1 ; inc pointer to msg
jmp loop
end: ;At the moment this just writes Msg to the framebuffer.
ret
; Clobbers r2, r3
; Params: r1 - string pointer
; Returns: r2, string length
fn strlen:
mov 0, r2 ; Set the length to zero
loop:
mov byte [r1], r3 ; mov char into r3
cmp r3, 0 ; NUL byte?
je end
inc r1 ; next char
inc r2 ; length++
jmp loop
end:
ret