- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to modify AN2101 for 16 bit divide.
The 8 bit version works fine but the 16 bit version just give trash.
this is the code, it is in assembly only
;We have [x+0], [x+1], The result will be in dividend+0 A1h ,dividend+1 A2h, ;Lets load the data
div_s_8::
mov [dividend+0],e0h ;we want to div this
mov [dividend+1],01h ;we want to div this
;
mov [divisor+0],02h ;Div by
mov [divisor+1],00h ;Div by 2
;div8:
mov [remainder+0],00h ;initialize remainder to 0
mov [remainder+1],00h ;initialize remainder to 0 New
;New
and F,fbh ;clear carry bit in flags
mov [lcount],16 ;set loop counter to 16 New changed from 8
d8u_1:
rlc [dividend+0] ;shift MSB of dividend to LSB of remainder
rlc [remainder+0] ; continued
rlc [dividend+1] ;shift MSB of dividend to LSB of remainder
rlc [remainder+1] ; continued
;
mov [temp+0],[remainder+0] ;store remainder
mov [temp+1],[remainder+1] ;store remainder New
;
mov a,[remainder+0] ;subtract divisor from remainder
sub a,[divisor+0] ; continued
mov [remainder+0],a ; continued
;New
mov a,[remainder+1] ;subtract divisor from remainder
sub a,[divisor+1] ; continued
mov [remainder+1],a ; continued
jnc d8u_2 ;jump if result was positive
;
mov [remainder+0],[temp+0] ;restore remainder
and [dividend+0],feh ;clear LSB of dividend
;New
mov [remainder+1],[temp+1] ;restore remainder
and [dividend+1],feh ;clear LSB of dividend
;
jmp chkLcount8 ;jump to loop counter decrement
d8u_2:
or [dividend+0],01h ;set dividend LSB to 1
;New
or [dividend+1],01h ;set dividend LSB to 1
;
chkLcount8:
dec [lcount] ;decrement loop counter
jnz d8u_1 ;repeat steps if loop counter not zero
;
ret ;back to caller
;******************************************************************************
Does anyone see the error ?
Thanks
Gord
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sampath
Since I cannot find a 16/16 divide for the PSoc 1 in assembly I have been force to go back to grade school and do the divide the hard way.
This is code , it may do a lot of loops but it gets the job done.
It subtracts the divisor from the dividend until it under flows, while counting the number of time through the loop.
It would have been nice to get something like AN2101 to do 16/16 but I do what i need to keep this project moving.
Please have a look around your office for an Old, Gray haired man that has a good working knowledge of assembly he mite be able to help.
Fore now I have a working solution.
Best regards,
Gord
This is the code:
;
div_s_16:: ;working Feb 28 2019 16/16 = 16
;Assembly:
;Setup values these are setup before calling div_s_16
; mov ,abh ;we want to div this HB
; mov ,cdh ;we want to div this LB
;
; mov ,00h ;Divisor HB
; mov ,05h ;Divisor LB
;
;The reuslt will be in LB & HB
mov ,00h ;clear the result
mov ,00h ;clear the result
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Gordon,
I request you to kindly refer to PSoC Designer Arithmetic Libraries User Guide.
On page 7, you will find arithmetic (Division, Reminder and Multiplication) functions for both signed and unsigned integers.
Best regards
Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sampath
I have tried the example 2.5 Unsigned Integer Division (16-bit) divu_16x16_16 but it cannot find the routine called DIVU_16x16_16, nor can it find the Include.
Your paper AN2101 works fine as a 8x8 divide but I have not being able to modify it for 16x16 uses.
Please bear in mind the project is all assembly.
I have tried to contact the author M.Ganesh Raaja to no avail, it is a short nice looking pice of code I would like to use it with the right changes.
Regards ,
Gord.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sampath
Correction the assembler can find divu_16x16_16 but cannot find the include.
I need to be clear here is the LSB of the dividend and is the MSB of the dividend.
Then is the LSB of the divisor and is the MSB of the divisor.
Correct me if I have this wrong because the result as I can see is always ffh, ffh
Best regards,
Gord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know why it did not come in the last email but the dividend is iOp1 and the divisor is iOp2.
Can you provide a sample lets say x01e0 / 0x0002 = ?? where is ??
Cheers,
Gord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot find the include.
How do I add this so I can use the 16x16 bit divide.
This should not be this hard.
0x???? / 0x???? = 0x????
This must be doable.
Gord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Gordon,
The project should build with the default include files. If not try including the following:
include "m8c.inc" ; part specific constants and macros
include "memory.inc" ; Constants & macros for SMM/LMM and Compiler
include "PSoCAPI.inc" ; PSoC API definitions for all User Modules
I am not an assembly language user, but I am trying my best to help you.
Best regards,
Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sampath
Since I cannot find a 16/16 divide for the PSoc 1 in assembly I have been force to go back to grade school and do the divide the hard way.
This is code , it may do a lot of loops but it gets the job done.
It subtracts the divisor from the dividend until it under flows, while counting the number of time through the loop.
It would have been nice to get something like AN2101 to do 16/16 but I do what i need to keep this project moving.
Please have a look around your office for an Old, Gray haired man that has a good working knowledge of assembly he mite be able to help.
Fore now I have a working solution.
Best regards,
Gord
This is the code:
;
div_s_16:: ;working Feb 28 2019 16/16 = 16
;Assembly:
;Setup values these are setup before calling div_s_16
; mov ,abh ;we want to div this HB
; mov ,cdh ;we want to div this LB
;
; mov ,00h ;Divisor HB
; mov ,05h ;Divisor LB
;
;The reuslt will be in LB & HB
mov ,00h ;clear the result
mov ,00h ;clear the result
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Gordon,
You can attach your a minimal version of your project. I will try to find why the divide routine is not found.
Best regards,
Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sampath
I have an incoming data stream coming from the RX8 module at 38,400 baud .
What I need is a timer module 16 bit that will reset on every chr received is as long as there are incoming data bytes the timer never calls the interrupt.
The timer has a 32,768 hz clock and is enabled.
So 32,768/16,384 = 2, 1/2 = 500e-3
When the data stream stops the timer expires and the timer interrupt is called.
When I get a chr I Stop the timer, Re-load the Period and Compare registers and then Re-Start the timer.
What is happening is the time interrupt goes off no mater what value I have in the period and compare registers.
I would like the timer to hold off the interrupt until 500ms has past without a re--set.
Can you tell me what's wrong.
This is the assembly code i'm using.
The timer is a 16 bit called recover.
;It has the interrupt set.
;No matter what value I have in the period and compare registers the Interrupt seem to happen almost right away.
;
;
;This is called in main loop when I get a RX8 chr.
;
lcall recover_Stop ;Stop the timer
;Reset the period reg
mov a,00h ;set the LSB of the period counter ;0x4000h = 16384 dec
mov 40h ;set the MSB of the period counter
lcall recover_WritePeriod ;set the period
;
;Reset the compare reg
mov a,00h ;set the LSB of the compare counter ;0x2000h = 8192 dec
mov x,20h ;set the MSB of the compare counter
lcall recover_WriteCompareValue ;set the period
;Restart the timer
nop
lcall recover_Start ;start the timer
;The rest of main loop
Cheers,
Gord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Gordon,
Can you kindly create a new thread for RX8/Timer Issue?
Best regards,
Sampath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do i do that ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sampath
I have that working now but in the debug mode when I stop I do not see the registers A,X, PC ect at the bottom of the screen any more.
I know you do not support designer 4.4 any more but there must be a quick fix for this ?
Anyone chime in please.
Gord