Re: Displaying string
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Thu, 31 Aug 2006 21:43:33 +0200
leon800219@xxxxxxxxx wrote:
Because Frank seems not to answer, I will try.
I've encounter a code snippet that is for string display, but there's
some points I don't understand, hope you help me thanks.
DispStr:
push ebp
mov ebp, esp
push ebx
push esi
push edi
; First of all what's ebp, I've searched but got no explicit
explanation
ebp is one of the 8 general purpose register
; what's the purpose of the above statements about manipulating ebp,
and esp
After the above code the stack looks like:
esp -> saved edi
saved esi
saved ebx
ebp -> saved ebp
return address
parameter (address of string)
mov esi, [ebp + 8] ; why pop 8 bytes?
[ebp]+8 -> parameter (address of string)
mov edi, [dwDispPos]
saved cursor position
mov ah, 0Fh
foreground/background color
.1:
lodsb
test al, al
jz .2
cmp al, 0Ah ; 0Ah stands for enter?
10 = 0x0a = line feed
jnz .3
push eax
mov eax, edi
mov bl, 160 ; what this 160 means?
80 character per line; 2 bytes for each charcter (ASCII code, color)
div bl
and eax, 0FFh
line number
inc eax
advance to next line
mov bl, 160
mul bl
mov edi, eax
new cursor position
pop eax
jmp .1
.3:
mov [gs:edi], ax
ax = color + ASCII code
gs: segment at physical address b8000 (video memory)
add edi, 2
update cursor position
jmp .1
.2:
mov [dwDispPos], edi
save cursor position
pop edi
pop esi
pop ebx
pop ebp
restor saved registers
ret
///////////////
; Here's the testing code
szRAMSize db "RAM size:", 0
push szRAMSize ;
parameter (address of string)
call DispStr ;
add esp, 4
There is a bug in this code: for a line feed it advances
to the next line without clearing the remaining characters
in the current line.
.
- References:
- Displaying string
- From: leon800219
- Displaying string
- Prev by Date: Re: Question about jumps
- Next by Date: Re: Question about jumps
- Previous by thread: Re: Displaying string
- Index(es):
Relevant Pages
|