
Bcd Numbers
Started by
huhn_m
, Mar 06 2004 10:06 AM
8 replies to this topic
#1
Posted 06 March 2004 - 10:06 AM
I need to write a proc that converts a 16 Bit number to a packet BCD for the calc.
There are specific nec instrictions I don't really understand.but how would you do
it with the normal methods you have?
The length of the num may be 1->5 Digits
Please help me!
btw. they start with a 0x10 and then the digit count-1 and the the digits.
So 1234 looks like:
0x1031234
There are specific nec instrictions I don't really understand.but how would you do
it with the normal methods you have?
The length of the num may be 1->5 Digits
Please help me!
btw. they start with a 0x10 and then the digit count-1 and the the digits.
So 1234 looks like:
0x1031234
#2
Posted 06 March 2004 - 11:12 AM
i will post in a minute, when i have looked at my notes from a class we had on BCD.
all i can remember at the moment is that it stands for Binary Coded Decimal
all i can remember at the moment is that it stands for Binary Coded Decimal
#3
Posted 06 March 2004 - 11:39 AM
it's ok. I tried somethings and it seems to work.
Please post your code though. Maybe it is better (Well I think it is
)
Here is my code:
Please post your code though. Maybe it is better (Well I think it is

Here is my code:
num2bcd proc ;AX = Number ;ES:DI = buffer PUSH AX MOV AL,10h STOSB;DO init number POP AX MOV CL,0 CMP AX,9 JNG @@do_numa INC CL CMP AX,99 JNG @@do_numa INC CL CMP AX,999 JNG @@do_numa INC CL CMP AX,9999 JNG @@do_numa INC CL @@do_numa: PUSH word ptr 0FFFFh MOV CH,CL MOV BX,10 XOR DX,DX @@loopera: DIV BX PUSH DX XOR DX,DX CMP CL,0 JE @@endea DEC CL JMP @@loopera @@endea:;-> All numbers are on stack in reverse Order POP AX MOV AH,CH SHL AL,4 SHR AX,4;-> Next byte is in AL! STOSB;-> Count + First num written! @@looperb: POP BX CMP BX,0FFFFh JE @@doneb POP AX CMP AX,0FFFFh JE @@done_wrb MOV AH,BL SHL AL,4 SHR AX,4;New num in AL STOSB;-> Written JMP @@looperb @@done_wrb: MOV AX,BX SHL AX,4 STOSB @@doneb: ret endp
#4
Posted 06 March 2004 - 11:53 AM
ahem.....
AHHHHHHHH!
i not like that ( idont understand it) . but i cant do any better, all i could give you is a method to convert form decimal to BCD, not a program!
sorry i cant be of much help.
oh i take it that this is going 2 be an AFX prog? if it is i would like to put it on my site, and we can appease 2072, by putting it in the filesharing
AHHHHHHHH!
i not like that ( idont understand it) . but i cant do any better, all i could give you is a method to convert form decimal to BCD, not a program!
sorry i cant be of much help.
oh i take it that this is going 2 be an AFX prog? if it is i would like to put it on my site, and we can appease 2072, by putting it in the filesharing


#5
Posted 06 March 2004 - 12:39 PM
it doesn't matter. Give me your method though maybe I can "convert" it to asm
since my routine has some starnge bug.
since my routine has some starnge bug.
#6
Posted 06 March 2004 - 10:08 PM
Well as i remember in BCD its something like this:
HEX..BCD..BIN
1........1...... 1
A......10.. 1010
B......11...1011
I nearly understand your code , only i dont remember by example what is the STOSB, i will think this afternoon (in my work) if there is another easiest way for do this.
HEX..BCD..BIN
1........1...... 1
A......10.. 1010
B......11...1011
num2bcd proc ;AX = Number ;ES:DI = buffer PUSH AX MOV AL,10h STOSB;DO init number POP AX MOV CL,0 CMP AX,9 JNG @@do_numa INC CL CMP AX,99 JNG @@do_numa INC CL CMP AX,999 JNG @@do_numa INC CL CMP AX,9999 JNG @@do_numa INC CL @@do_numa: PUSH word ptr 0FFFFh MOV CH,CL MOV BX,10 ***********************In the instruction with the *** i think it must be 10 Dec, or 0AH, right?
I nearly understand your code , only i dont remember by example what is the STOSB, i will think this afternoon (in my work) if there is another easiest way for do this.
#7
Posted 07 March 2004 - 06:03 AM
1) Yes it has to be 10 DEC (0Ah), I uses TASM syntax
2) STOSB writes the byte in AL to the memory at ES:DI
2) STOSB writes the byte in AL to the memory at ES:DI
#8
Posted 07 March 2004 - 06:33 AM
I will try to do this tomorrow (my brain cant give me more today).it doesn't matter. Give me your method though maybe I can "convert" it to asm since my routine has some starnge bug
#9
Posted 07 March 2004 - 09:52 AM
im having trouble finding my notes, i think my friend has them, i will ask him...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users