Jump to content



Photo
- - - - -

Bcd Numbers


  • Please log in to reply
8 replies to this topic

#1 huhn_m

huhn_m

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1957 posts
  • Gender:Male
  • Location:Germany / Dresden
  • Interests:Assembler(!!!)
    Computers and Programming
    Operating Systems
    Programmable Calculators
    Maths and everything arround it

  • Calculators:
    FX-82SX / AFX 2.0+ (ROM 1.03) / FX 1.0+ (ROM 1.03)

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

#2 Andy.Davies

Andy.Davies

    Forum Ghost

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1547 posts
  • Gender:Male
  • Location:Dorset, England
  • Interests:Age: 18
    Studying: MEng in cybernetics at Reading uni
    Interests: Progaming (VB, VB.Net, C#, Casio Basic)
    Computers UBBD (Using, Building, Breaking & Destroying)
    Gaming (FPS, RTS, RPG)
    Electronics
    Rock Music (Preferably Loud)
    Riley's (Pool & Snooker Bar)
    Driving (Preferably fast)
    Aikedo (Martial Art)

  • Calculators:
    Algebra FX 2.0 ROM 1.01, FX9750G

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

#3 huhn_m

huhn_m

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1957 posts
  • Gender:Male
  • Location:Germany / Dresden
  • Interests:Assembler(!!!)
    Computers and Programming
    Operating Systems
    Programmable Calculators
    Maths and everything arround it

  • Calculators:
    FX-82SX / AFX 2.0+ (ROM 1.03) / FX 1.0+ (ROM 1.03)

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:

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 Andy.Davies

Andy.Davies

    Forum Ghost

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1547 posts
  • Gender:Male
  • Location:Dorset, England
  • Interests:Age: 18
    Studying: MEng in cybernetics at Reading uni
    Interests: Progaming (VB, VB.Net, C#, Casio Basic)
    Computers UBBD (Using, Building, Breaking & Destroying)
    Gaming (FPS, RTS, RPG)
    Electronics
    Rock Music (Preferably Loud)
    Riley's (Pool & Snooker Bar)
    Driving (Preferably fast)
    Aikedo (Martial Art)

  • Calculators:
    Algebra FX 2.0 ROM 1.01, FX9750G

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 ;) :lol2:

#5 huhn_m

huhn_m

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1957 posts
  • Gender:Male
  • Location:Germany / Dresden
  • Interests:Assembler(!!!)
    Computers and Programming
    Operating Systems
    Programmable Calculators
    Maths and everything arround it

  • Calculators:
    FX-82SX / AFX 2.0+ (ROM 1.03) / FX 1.0+ (ROM 1.03)

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.

#6 betoe

betoe

    UCF Spanish Translator

  • [Legends]
  • PipPipPipPipPipPipPip
  • 846 posts
  • Gender:Male
  • Location:Guadalajara/Mazatlan, Mexico.
  • Interests:Electronics, SW development, automotive. Swim->bike->run

  • Calculators:
    Algebra FX2.0 (R.I.P.), Classpad 300

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

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 huhn_m

huhn_m

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1957 posts
  • Gender:Male
  • Location:Germany / Dresden
  • Interests:Assembler(!!!)
    Computers and Programming
    Operating Systems
    Programmable Calculators
    Maths and everything arround it

  • Calculators:
    FX-82SX / AFX 2.0+ (ROM 1.03) / FX 1.0+ (ROM 1.03)

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

#8 betoe

betoe

    UCF Spanish Translator

  • [Legends]
  • PipPipPipPipPipPipPip
  • 846 posts
  • Gender:Male
  • Location:Guadalajara/Mazatlan, Mexico.
  • Interests:Electronics, SW development, automotive. Swim->bike->run

  • Calculators:
    Algebra FX2.0 (R.I.P.), Classpad 300

Posted 07 March 2004 - 06:33 AM

it doesn't matter. Give me your method though maybe I can "convert" it to asm since my routine has some starnge bug

I will try to do this tomorrow (my brain cant give me more today).

#9 Andy.Davies

Andy.Davies

    Forum Ghost

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1547 posts
  • Gender:Male
  • Location:Dorset, England
  • Interests:Age: 18
    Studying: MEng in cybernetics at Reading uni
    Interests: Progaming (VB, VB.Net, C#, Casio Basic)
    Computers UBBD (Using, Building, Breaking & Destroying)
    Gaming (FPS, RTS, RPG)
    Electronics
    Rock Music (Preferably Loud)
    Riley's (Pool & Snooker Bar)
    Driving (Preferably fast)
    Aikedo (Martial Art)

  • Calculators:
    Algebra FX 2.0 ROM 1.01, FX9750G

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