help

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Sum Dude

help

Post by Sum Dude »

Has anyone got a peice of code (in nasm) that (using lodsb and no stack or anything like that) reads a byte and displays it?

(dont want to use any int21 stuff)

Thanx
Guest

RE:help

Post by Guest »

>On 2002-03-15 16:13:47, Sum Dude wrote:
>Has anyone got a peice of code (in nasm) that (using lodsb and no stack or anything like that) reads a byte and displays it?

i got it! if you mean to display the byte as it is...

>(dont want to use any int21 stuff)

you copy the string, whatever you want to print pointed with si, with lodsb to al and then put 0x07 (for normal format) in ah, and then mov [es:di],ax for es:di=>0xb800:(offset within 1 page on the screen) or es:di=>0xb000:(offset) if you have monochrome CRT. Do place the string, set conditions such as or al,al, then jz .done, like a while(...){} loop.

You can view a copy of my bootsector (that's where i'm testing my I/O functions w/o even BIOS), I've messed it up completely (but have some good functions written), so I'm writing a new one starting from scratch again thus I have no copies of it on the internet...but here is a sneak peak:

;; sprintf(char *string, int offset)

;; usage:
;; -----
;; mov byte ax,0 ; some kind of offset
;; push ax
;; move byte ax,string1 ;pointer to string
;; push ax
;; call sprintf ; call the f(x)
;; -----
;; this one is a near call, so takes argument from
;; bp+4 as first one
;; if you plan on to use a far call the arguments
;; are loaded as bp+6
sprintf:

push bp ; saves bp

mov bp,sp ; prepares bp for arguments

pusha ; prepare stack



mov di,0xb800 ; move in the video ram

mov es,di ; set es

mov di,[bp+6] ; set di to destinated offset

mov byte si,[bp+4] ; load string to print



.begin: ; while (pre-condition) {

mov ah,0x0f ; set attribute

lodsb ; load 1 byte from string



cmp al,0x00 ; if (al == 0x00)

jz .done ; true: done



mov word [es:di],ax ; otherwise override into mem

add di,2 ; add to bytes to video counter

jmp .begin ; } // loop back

.done:

mov bp+6,di

popa

leave

ret



That's it...
Sum Dude

RE:help

Post by Sum Dude »

Thanx alot, you've been very helpful.
Post Reply