Files
lang-assm/examples/strlen.asm
T

37 lines
1.1 KiB
NASM

namespace string 67; my string namespace here
namespace text "some string in the middle of nowhere";do you do this?
word FRAMEBUFFER 0x00200500
asciiz Msg "Hello World!"
; fn effectively is an "Append to Namespace" command, ie string + "." + _start
fn _start:;do you do this?
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?
jz end
mov byte r3, [r32]; Write char to frame buffer
add 1, r32 ; Next space in framebuffer
add 1, r4 ; inc counter
add 1, 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?
jz end
add 1, r1 ; next char
add 1, r2 ; length++
jmp loop
end:
ret