Printing a string directly to the video memory

Programming, for all ages and all languages.
Post Reply
leosa99
Posts: 21
Joined: Tue Aug 30, 2016 9:34 am
Libera.chat IRC: leosa99

Printing a string directly to the video memory

Post by leosa99 »

Hi !
I made a function to print the SI register on the screen directly through the video memory.
It's weird but this function only write the first character ...

Code: Select all

writeCharacterToVideoMemoryFunc: ; al=character ah=attributes cx=offset(byte)
mov esi, 0xB8000
add si, cx
mov byte [esi], al
mov byte [esi+1], ah
ret

writeSIToVideoMemory: ; cx=offset
mov al, [si]
cmp al, 0
je end
mov ah, 00001111b
call writeCharacterToVideoMemoryFunc
inc si
add cx, 2d ; inc cx 2 times
jmp writeSIToVideoMemory
end:
ret
I call it with this code :

Code: Select all

mov si, MSG
mov cx, 40d
call writeSIToVideoMemory
jmp $

MSG: db "OK !", 0
I run it in protected mode.
Thanks !
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Printing a string directly to the video memory

Post by iansjack »

Your WriteCharacter routine trashes SI, which is going to cause problems.
leosa99
Posts: 21
Joined: Tue Aug 30, 2016 9:34 am
Libera.chat IRC: leosa99

Re: Printing a string directly to the video memory

Post by leosa99 »

I'm dumb.
Thanks
Post Reply