Advertisement

assembly question

Started by April 05, 2001 01:46 PM
8 comments, last by a2k 23 years, 10 months ago
hey guys, whoever knows assembly, i need help: i want to convert AX (16 bit integer) and resolve it into its component digits into an 8-byte string. so, i wanna do this: number db 8 dup(0) lea si, number and lodsb for each resolved digit of the integer in AX i know it involves dividing by 10 and taking the remainder, but the code i got from my book doesn''t seem to work or something. i''ve tried doing this, but i don''t get the right answer. i''m a beginner in assembly too, so please bear with me. do any of you have any assembler source to do this, or any links to source? thanks a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
It has been a long time, but a little assembly could be fun...

    ; eax = value to be converted  xor   ecx,ecx  mov   ebx,10  mov   edi, offset numberpleaseloopme:         ; divide and save remainder  xor   edx,edx  div   ebx   push  edx  inc   ecx  or    eax,eax  jnz   pleaseloopmepleasereadme:  dec   ecx           ; read back stack  jc    done  pop   eax  add   al, ''0''  mov   [edi],al  inc   edi  jmp   pleasereadmedone:  mov   [edi], 0      ; zero terminate string  ; used: eax,ebc,ecx,edx,edi, stackload 5 dwords  ; "number" filled with ASCII decimal number    


I guess this is enough assembly for me this year

Advertisement
hey, thanks, bas

seem to save me all the time.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
darn it,

that''s not what i wanted. my binary->ascii already works. my ascii->binary doesn''t work.

sorry.

the thing is, it only works if the string is terminated with a ''$'' it has to be terminated with anything other than digits.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
I think it would be easier like this:

mov di, offset number+5
mov dl, 0
mov es:[di], dl
dec dl

mov bx, 10
mov cx, 5
repeat:
xor dx, dx
div bx
add dl, ''0''
mov es:[di], dl
dec di
dec cx
jnz repeat

I am too tired and too much in a hurry to write any comments or check if it actually works.
ascii->binary...hmmm...even easier.

I wasn''t planning on doing more assembly this year, but what the heck...
Now in speed optimised 32bit
    ; esi = ptr to ASCII string ''$'' terminated, must be filled!  xor   ebx,ebx  mov   cl,''$''  xor   eax,eax  mov   bl,[esi]  inc   esiacceptchar:    lea   eax,[eax*4+eax]  add   bl, ''0''  add   eax,eax  add   eax,ebx    mov   bl,[esi]  inc   esi  cmp   bl,cl  jnz   SHORT acceptchardone:  ; eax = the highspeed result  ; ebx,ecx,esi are used  


C''mon guys, you''re missing all the fun in using 32 bit assembly !
Linear megabyte buffers, no more segment worries, and fast full 32bit regs

Advertisement
And to much assembly can make you go CraZy!
i''m actually taking an assembly class right now, and we''re not even using the extended registers. not sure how to do it this way. i''ve been working with measly 16-bit numbers. that''s all i need for this stupid project.

hey bas, was that code runnable or were you going off of it in your head? did you run it inline in visual c++? if so, how do you do it? not sure how to get my c++ compiler to run inline assembly.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
nevermind, found it in MSDN

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
a2k: Top of my head. Never tested it. So there''s a good chance I''m missing something.


AP:

This topic is closed to new replies.

Advertisement