Code-explanation

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

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">mov cx,ax

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">pop ax

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">; before div: DX=intermediate remainder, AX=dividend LSW, BX=divisor

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">; after div: AX=quotient LSW, DX=remainder

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">div bx

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">; end: DX=quotient MSW, AX=quotient LSW, CX=remainder

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">xchg dx,cx

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">add cl,'0'

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">cmp cl,'9'

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">jbe wrnum2

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">add cl,('A'-('9'+1))

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">wrnum2:

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">dec si

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">mov [si],cl

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">mov cx,ax

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">or cx,dx

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">jne wrnum1

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">call cputs

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">pop ax

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">pop cx

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">pop dx

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">pop si

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">ret

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">下面是解释：

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">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.

<p style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-family:Simsun;font-size:medium;line-height:normal;">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.