Re: about nasm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/12/06, Tristan Li <linuxren@xxxxxxxxx> wrote:
Hi nerds:

I've been reading an article on the booting process. The part about
detecting the memory amount really confused me.
wrnum:

 push si
 push dx

 push cx
 push ax
 mov si,num_buf


; extended precision division from section 9.3.5
; of Randall Hyde's "Art of Assembly"

; start: DX=dividend MSW, AX=dividend LSW, BX=divisor
wrnum1:

 push ax
 mov ax,dx

 xor dx,dx

; before div: DX=0, AX=dividend MSW, BX=divisor

; after div: AX=quotient MSW, DX=intermediate remainder
 div bx

 mov cx,ax
 pop ax

; before div: DX=intermediate remainder, AX=dividend LSW, BX=divisor

; after div: AX=quotient LSW, DX=remainder
 div bx


; end: DX=quotient MSW, AX=quotient LSW, CX=remainder
 xchg dx,cx

 add cl,'0'
 cmp cl,'9'

 jbe wrnum2
 add cl,('A'-('9'+1))
wrnum2:

 dec si
 mov [si],cl


 mov cx,ax
 or cx,dx
 jne wrnum1

 call cputs
 pop ax
 pop cx

 pop dx
 pop si

 ret

I'm just wondering what's the code above doing? I really can not understand
it.
Can anyone help me?
Many thx!

hi, first of all, the code snippet you have given is doing only the
printing the 32-bit number in a specified radix. its not part of any
memory detection routine. i think you havent't completely gone through
the comments given along with the code.

its just dividing the number with the radix, each time getting the
least significant number, converting to printable ascii format in the
range '0' - '9' and 'A' - 'Z' (though not limited to 'Z'), storing the
result in the reverse order starting from the address num_buf(you can
notice a 40 bytes array declared just above the address) and after the
conversion is over cputs is called to print the formed string.

i hope i've explained enough.

The original code can be found at
http://my.execpc.com/~geezer/osd/boot/size.asm
Sorry for my english :-(

--
My blog: http://lijie.org

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux