Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Conditional assembly....on a PIC..

Status
Not open for further replies.

Buriedcode

Full Member level 6
Joined
May 6, 2004
Messages
357
Helped
43
Reputation
86
Reaction score
7
Trophy points
1,298
Location
London
Activity points
8,887
Hi,

I'm currently designing a PWM controller for PIC, I've explained my algorithm in another topic, however, it requires that I put the contents of 3 registers in order of size. Also, to keep track of which register the contents came from, a further 3 registers which have a value that represents the register its from....hope you're still with me :D

So, for example, say I have 3 registers, called, A, B and C. I have put a random 8-bit number in each one. I need to have 6 registers in the output.....I'll call them:
'smallest', 'middle' and 'largest'. Also, to keep track on whats contents belongs to which register (A,B or C) the other 3 registers in the output are 'smlreg' 'midreg' and 'lrgreg'. Say, the contents of the 'A' register, happens to be the smallest out of all 3, it contains the decimal value '23'. I would put d'23' in the 'smallest' register, and put '1' in the 'smlreg' register. Maybe the contents of 'C' would be the middle value, I would then put the contents of it in the 'middle' register, and put '3' in the 'midreg' register. (thus, contents of 'B' go in the 'largest' reg', with '2' in 'lrgreg' register.

Now, I realise that its really complicated, and any higher level languages could do this in spades (PICbasic, C etc..) but I would like to do this in assembly.

I've read a little on 'conditional' assembly, and I've seen code written in the form :

IF tempreg > 0x7F
[Do something]
ELSEIF tempreg < 0x26
[Do something else]
ELSE
[leave everything alone]
ENDIF

Now, I am unsure what I can do with this? Is it for 'bit operations' (like checking bit 7 of PORTA, and flags) or can it be used for comparing contents of registers? (like IF temp1 > temp2). The only context I've seen this used is calculating delays.

Now, I'm still fairly new to assembly, and I can only assume that this is a sort of 'macro' that MPASM uses, and the output code (hex) would in fact take more than 1 instruction cycle for 'IF' because the compiler would replace it with instructions that perform exactly what I want.

It would make my algorithm a whole lot easier since I could just:

IF A > B
movf A,W
movwf HIGHEST
movf B,W
movwf LOWEST
ELSEIF B < A
movf B,W
movwf HIGHEST
movf A,W
movwf LOWEST
ELSEIF A = B
you get the idea....:)

If anyone could help me with this algorithm, or explain if I can in fact use 'IF-THEN-ELSE' on registers and their contents I would be grateful. If not, then I'll have to write it all in pure asm, which frankly, I'm not looking forward to :(


Thanks,

BuriedCode.
 

No. Conditional assebly is not an instruction. It is an assembler directive or pseudo-code. A directive generate not any code. IF-THEN-ELSE tell you the code you going to assemble,,,,not the code you execute.
You need to implement conditional block by assembler.


//Felipe
 

    Buriedcode

    Points: 2
    Helpful Answer Positive Rating
Hola B C,

You need to write pure asm code. Those assembler directives are for when assembling and what you need to give is instructions for the micro to follow at running time.

I don't know if you do it but I always draw first the flow diagrams to decide how the checking will be done. And then use the sequence of required comparisons more convenient for the case.

To avoid confusing myself I use, always, macros, which I wrote on purpose, long time ago.

You could look for them here, if you like:
http://cablemodem.fibertel.com.ar/atferrari/

I've spent few days writing them and forgot the details in checking this or that flag forever.

Buena suerte

Agustín Tomás
 

    Buriedcode

    Points: 2
    Helpful Answer Positive Rating
Hi people,

Thanks for your replies! I guessed that it wouldn't be that easy :(
But atferrari, those macros really will help. Since I need to put them in order of size (compare two registers) and also check if each register is 0 or 255 (PWM always off, or always on). The code is going to be monsterous, but with macro's, and possibly subroutines (if variables remain in the subroutine) it shouldn't be that hard to write. I nearly always use an ASM chart (flow diagram) for software, then pseudo-code (IF's THEN's ELSE's etc..) before writing my final beta version. Hopefully I can indeed shorten it a little.

I'll post any success in that PWM topic, in this forum. Maybe it can help someone who wishes to run an LCD, 8 LED's PWM'ed, keyboard and UART.

Thanks again guys, knew you had the answers.

Buriedcode.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top