### Don't have a Xilinx account yet?

• Choose to receive important news and product information
• Personalize your web experience on Xilinx.com

Create Account

XClose Panel

## PicoBlaze

Visitor
Posts: 4
Registered: ‎10-08-2010

# 2x 8 bit BCD

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

;
;		 SHIFT WITH UNITS AND UNITS
;

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

Xilinx Employee
Posts: 413
Registered: ‎09-05-2007

# Re: 2x 8 bit BCD

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

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.

Ken Chapman
Principal Engineer, Xilinx UK
Visitor
Posts: 4
Registered: ‎10-08-2010

# Re: 2x 8 bit BCD

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,

Visitor
Posts: 4
Registered: ‎10-08-2010

# Re: 2x 8 bit BCD

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;
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
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
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
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
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
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
ret;

;
; -------------------------------------------
; INIT NUMBERS AT START
; -------------------------------------------
;

;
;  From 2x8 bit to 4x4 bit
;
INIT_NUMBERS:
AND NUM1, \$0F
SR0 NUM2
SR0 NUM2
SR0 NUM2
SR0 NUM2

AND NUM3, \$0F
SR0 NUM4
SR0 NUM4
SR0 NUM4
SR0 NUM4
ret;

;
; -------------------------------------------
; ADD NUMBER TO CERTAIN NUMx_END AND HANDLE CARRY
; -------------------------------------------
;

;
;
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
ret;

;
;
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
ret;

;
;
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
ret;

;
;
ret;```

Expert Contributor
Posts: 7,505
Registered: ‎07-21-2009

# Re: 2x 8 bit BCD

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;
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

SIGNATURE:

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.
Visitor
Posts: 4
Registered: ‎10-08-2010

# Re: 2x 8 bit BCD

[ Edited ]

Oh this seems to be working:

This one won't jump in the second JUMP.

Code fixed:

```LOAD TMP1, 5;
COMP TMP1, 2;
JUMP NC, SPLITTER;           LOAD TMP1, 1;
COMP TMP1, 2;
JUMP NC, SPLITTER;```
Visitor
Posts: 2
Registered: ‎04-21-2012

# Re: 2x 8 bit BCD

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;```
Visitor
Posts: 2
Registered: ‎04-21-2012

# Re: 2x 8 bit BCD

Sorry if the answer to my question is too obvious is just that I looked in the code where did you jump to SPLITTER and I didn´t found it.... Also if you could share the complete code it would be a lot of help for me...

Expert Contributor
Posts: 7,505
Registered: ‎07-21-2009

# Re: 2x 8 bit BCD

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

SIGNATURE: