- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-08-2010 03:33 AM
Hello,
What i got: 2x 8 bit, combined 1x 16bit number.
What i need: 4x 4bit. Each number on it's own.
This is what i got atm:
; Number 4321
number_in_one DSIN 00 ; Input number (21)
number_in_two DSIN 01 ; Input number (43)
number_out_one DSOUT 00 ; Right number out (1)
number_out_two DSOUT 01 ; Right number out (2)
number_out_three DSOUT 02 ; Right number out (3)
number_out_four DSOUT 03 ; Right number out (4)
TMP1 EQU s7 ;
TMP2 EQU sF ;
NUM1 EQU s0 ;
NUM2 EQU s1 ;
NUM3 EQU s2 ;
NUM4 EQU s3 ;
BEGIN:
IN TMP1, number_in_one
CALL SPLITTER
OUT NUM1, number_out_one
OUT NUM2, number_out_two
; IN s0, number_in_two
; CALL SPLITTER
; OUT NUM3, number_out_three
; OUT NUM4, number_out_four
JUMP BEGIN
SPLITTER :
;
; SHIFT WITH UNITS
;
SL0 TMP1 ; SHIFT LEFT AND ADD 0
SLA NUM1 ; ADD CARRY BIT TO NUM1
SL0 TMP1
SLA NUM1
SL0 TMP1
SLA NUM1
COMP NUM1, $4 ; Check if number is larger then 4
ADD NUM1, 3 ; ADD 3
;
; SHIFT WITH UNITS AND UNITS
;
LOAD TMP2, NUM1
RET
The problem, it will allways add the 3 to NUM1, i don't understand why.If the number is not larger then 4 it will still add 3.
My other problem is that i need 4x 4bit and with shifting that go's wrong, example:
input: 11111111
After 3 shift: NUM1: 1010
Now i shift again and the 1 (left one) should go to NUM2 and then i need to shift 1 more time from the input to NUM1. So the result would be:
NUM1: 0101
NUM2: 0001
But i don't understand how to do this, i have read the manual but can't figure this out.
Anyone know's how to do this and can help me out?
Cheers,
Niels
Solved! Go to Solution.
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-08-2010 07:31 AM
I’m not really sure what you are trying to do yet but I will make a few comments and see if they help you.
You call a routine called ‘SPLITTER’ which takes what you have provided in ‘TMP1’ and starts to make a new value in ‘NUM1’.
You don’t appear to initialize ‘NUM1’ so as you shift data into it any old data is still in there and just gets shifted too. Do you really want to do that?
Three times you shift the most significant bit out of TMP1 into the carry flag and then shift the carry flag into the least significant bit of NUM1. Hence the data you shift is ending up in the lower 3 bits of NUM1 where they will give NUM1 a potential value of up to 07 hex. That could be bigger than 4 but will always be bgger than 4 if you didn't initialse NUM1 to clear any other '1's first.
Why do you shift only 3 times rather than 4?
You always add 3 because you always execute the ADD instruction. Your compare instruction needs to be followed by a conditional JUMP ('JUMP C, label' or similar) if you don’t want to do something under certain conditions.
Here is what I would do to split an 8-bit value into 2 x 4-bits...
Assume 8-bit value is in s3 to start
LOAD s2, s3
AND s2, 0F
SR0 s3
SR0 s3
SR0 s3
SR0 s3
The upper nibble is in the lower nibble of s3.
The lower nibble is in the lower nibble of s2.
Principal Engineer, Xilinx UK
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-10-2010 03:00 AM
Thanks for you reply, I will keep on trying.
What I'm trying to make is:
- Send 2, 8 bit numbers to the Assembly. Together 1 number of 4 digits.
- Split the "16" bit number (2x8 bit) into 4 seperated numbers.
Example input:
4123 : 00010000 00011011
Example output:
4 : 00000100
1 : 00000001
2 : 00000010
3 : 00000011
That's what im trying to make.
Cheers,
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-11-2010 09:05 AM
Hello,
I'm pretty far now. But still got the problem with the COMP. It alwasy JUMP's (In the pBlaze IDE Picoblaze III), code:
Even if i just do someting like this:
LOAD TMP1, 5; COMP TMP1, 2; JUMP SPLITTER;
LOAD TMP1, 1; COMP TMP1, 2; JUMP SPLITTER;
Above code jumps in both COMP functions. Why?
My code ATM:
; optellen van getallen, rechter 4 bits $3, linker 4 bits $30 (is namelijk HEX)
; Kijken naar de carry bit van rechter 8 naar linker 8 bits
; Number 4321
number_in_one DSIN 00 ; Input number (21)
number_in_two DSIN 01 ; Input number (43)
number_out_one DSOUT 00 ; Right number out (1)
number_out_two DSOUT 01 ; Right number out (2)
number_out_three DSOUT 02 ; Right number out (3)
number_out_four DSOUT 03 ; Right number out (4)
TMP1 EQU sD ;
TMP2 EQU sF ;
TMP3 EQU sE ;
NUM1 EQU s0 ;
NUM2 EQU s1 ;
NUM3 EQU s2 ;
NUM4 EQU s3 ;
NUM1_END EQU s4 ;
NUM2_END EQU s5 ;
NUM3_END EQU s6 ;
NUM4_END EQU s7 ;
BEGIN:
IN TMP1, number_in_one
IN TMP2, number_in_two
CALL SPLITTER
OUT NUM1_END, number_out_one
OUT NUM2_END, number_out_two
JUMP BEGIN
SPLITTER :
; Make 4x4 bit
CALL INIT_NUMBERS;
; RESET carry
LOAD TMP2, 0;
LOAD TMP1, NUM1;
CALL SHIFT_ONCE_NUM1;
RET
;
; Shift the TMP1 and set shifted number in TMP2
; IN TMP1 = Number
; OUT TMP1 = Number
; OUT TMP2 = Shifted Number
;
SHIFT:
SL0 TMP1 ; SHIFT LEFT
LOAD TMP2, TMP1 ;
AND TMP1, $0F ; AND WITH 00001111
SR0 TMP2 ; SHIFT RIGHT, SO IT WILL BE 00000001
SR0 TMP2 ;
SR0 TMP2 ;
SR0 TMP2 ;
ret;
;
; -------------------------------------------
; SHIFT NUMBER
; SHIFT TMP1 INTO CERTAIN NUMx_END
; -------------------------------------------
;
;
; Shift Once
;
SHIFT_ONCE_NUM1:
; LOAD TO TMP AND SHIFT
CALL SHIFT ; Shift the TMP1
LOAD NUM1, TMP1 ; Set num 1 from shifted tmp
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1
CALL ADD_NUM1 ; ADD THE CARRY BIT TO NUM1
ret;
;
; Shift Once
;
SHIFT_ONCE_NUM2:
; LOAD TO TMP AND SHIFT
CALL SHIFT ; Shift the TMP1
LOAD NUM1, TMP1 ; Set num 1 from shifted tmp
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1
CALL ADD_NUM2 ; ADD THE CARRY BIT TO NUM1
ret;
;
; Shift Once
;
SHIFT_ONCE_NUM3:
; LOAD TO TMP AND SHIFT
CALL SHIFT ; Shift the TMP1
LOAD NUM1, TMP1 ; Set num 1 from shifted tmp
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1
CALL ADD_NUM3 ; ADD THE CARRY BIT TO NUM1
ret;
;
; Shift Once
;
SHIFT_ONCE_NUM4:
; LOAD TO TMP AND SHIFT
CALL SHIFT ; Shift the TMP1
LOAD NUM1, TMP1 ; Set num 1 from shifted tmp
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1
CALL ADD_NUM4 ; ADD THE CARRY BIT TO NUM1
ret;
;
; -------------------------------------------
; INIT NUMBERS AT START
; -------------------------------------------
;
;
; From 2x8 bit to 4x4 bit
;
INIT_NUMBERS:
LOAD NUM2, TMP1;
LOAD NUM1, TMP1
AND NUM1, $0F
SR0 NUM2
SR0 NUM2
SR0 NUM2
SR0 NUM2
LOAD NUM4, TMP2;
LOAD NUM3, TMP2
AND NUM3, $0F
SR0 NUM4
SR0 NUM4
SR0 NUM4
SR0 NUM4
ret;
;
; -------------------------------------------
; ADD NUMBER TO CERTAIN NUMx_END AND HANDLE CARRY
; -------------------------------------------
;
;
; ADD TMP1 to NUM1_END
;
ADD_NUM1:
ADD NUM1_END, TMP1 ; ADD number
LOAD TMP2, NUM1_END ;
AND NUM1_END, $0F ; AND WITH 00001111
SR0 TMP2 ; SHIFT RIGHT, SO IT WILL BE 00000001
SR0 TMP2 ;
SR0 TMP2 ;
SR0 TMP2 ;
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1, this is the output
COMP TMP1, 0 ; Check if Number is larget then 0
JUMP ADD_NUM2 ; Add to number 2 if needed
ret;
;
; ADD TMP1 to NUM2_END
;
ADD_NUM2:
ADD NUM2_END, TMP1 ; ADD number
LOAD TMP2, NUM2_END ;
AND NUM2_END, $0F ; AND WITH 00001111
SR0 TMP2 ; SHIFT RIGHT, SO IT WILL BE 00000001
SR0 TMP2 ;
SR0 TMP2 ;
SR0 TMP2 ;
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1, this is the output
COMP TMP1, 0 ; Check if Number is larget then 0
JUMP ADD_NUM3 ; Add to number 2 if needed
ret;
;
; ADD TMP1 to NUM3_END
;
ADD_NUM3:
ADD NUM3_END, TMP1 ; ADD number
LOAD TMP2, NUM3_END ;
AND NUM3_END, $0F ; AND WITH 00001111
SR0 TMP2 ; SHIFT RIGHT, SO IT WILL BE 00000001
SR0 TMP2 ;
SR0 TMP2 ;
SR0 TMP2 ;
LOAD TMP1, TMP2 ; LOAD TMP2 into TMP1, this is the output
COMP TMP1, 0 ; Check if Number is larget then 0
JUMP ADD_NUM4 ; Add to number 2 if needed
ret;
;
; ADD TMP1 to NUM4_END
;
ADD_NUM4:
ADD NUM4_END, TMP1 ; ADD number
ret;
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-11-2010 09:50 AM
But still got the problem with the COMP. It always JUMP's (In the pBlaze IDE Picoblaze III), code:
Even if i just do someting like this:
LOAD TMP1, 5; COMP TMP1, 2; JUMP SPLITTER;
LOAD TMP1, 1; COMP TMP1, 2; JUMP SPLITTER;Above code jumps in both COMP functions. Why?
JUMP (without Z | NZ | C | NC conditional modifier) is unconditional. If it did not always jump, that would be a problem.
-- Bob Elkind
README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369
Summary:
1. Read the manual or user guide. Have you read the manual? Can you find the manual?
2. Search the forums (and search the web) for similar topics.
3. Do not post the same question on multiple forums.
4. Do not post a new topic or question on someone else's thread, start a new thread!
5. Students: Copying code is not the same as learning to design.
6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).
7. You are not charged extra fees for comments in your code.
8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.
Re: 2x 8 bit BCD
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-11-2010 09:56 AM - edited 10-11-2010 10:01 AM
Oh this seems to be working:
This one won't jump in the second JUMP.
Thnx for your help!
Code fixed:
LOAD TMP1, 5; COMP TMP1, 2; JUMP NC, SPLITTER;
LOAD TMP1, 1; COMP TMP1, 2; JUMP NC, SPLITTER;
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-21-2012 06:02 PM
So, where in the code goes this???
LOAD TMP1, 5; COMP TMP1, 2; JUMP NC, SPLITTER;
LOAD TMP1, 1; COMP TMP1, 2; JUMP NC, SPLITTER;
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-21-2012 06:06 PM
Thank you in advance
Re: 2x 8 bit BCD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-21-2012 06:16 PM
Alsonso,
Why not write your own code?
If you write your own code, you will understand the code, and you will be able to debug it.
Otherwise, you will need both the code and a step-by-step explanation of how the code works, correct?
And how do you know the code posted in this thread is suited to your application?
-- Bob Elkind
README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369
Summary:
1. Read the manual or user guide. Have you read the manual? Can you find the manual?
2. Search the forums (and search the web) for similar topics.
3. Do not post the same question on multiple forums.
4. Do not post a new topic or question on someone else's thread, start a new thread!
5. Students: Copying code is not the same as learning to design.
6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).
7. You are not charged extra fees for comments in your code.
8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.











