Assembly Programming

Thread Starter

MstrKurt

Joined Oct 26, 2013
18
Hey guys,

I'm in need to learn Assembly Programming in some detail and rather fast too.
I am aiming to create an audio processing pedal that will use various effects such as Distortion, Delay, Chorus etc...

Distortion must be done by the beginning of January.

Is there somewhere that explains Assembly in detail from the very beginning?

Thanks.
 

Thread Starter

MstrKurt

Joined Oct 26, 2013
18
I'm learning on a PIC18F45K20 from the board that comes with the PICkit 3.

For my project I will be using a DSPIC33FJ32GP302. Also, I understand microcontrollers but have no knowledge on coding them.
 
Last edited:

MaxHeadRoom

Joined Jul 18, 2013
28,617
The examples on assembly out there is geared more to the 16F, such as http://www.winpicprog.co.uk/pic_tutorial.htm there is also PICLIST and the PicMicro site itself for app notes featuring the individual modules in the 18F etc complete with program examples to use as a base.
I started out using the pic 16F but migrated to the 18F which I find easier using assembly and more a powerfull processor.
There is a fairly decent book out there on the PIC18 programming by Han-Way Huang and Leo Chartrand, Introduction to the PIC18 Microcontroller, It is out there in PDF, if you have a problem finding it, I can send a copy over.
I believe the hard copy price is around $300.
Max.
 

Thread Starter

MstrKurt

Joined Oct 26, 2013
18
Thanks for your reply guys.

I have found some "tutorials" if you can call them that on the microchip website. I managed to complete tutorial one which is just turning LED's on, but I'm stuck on number two which is making LED's blink.

This was tutorial 1:
Start:
banksel TRISC ; select bank1
bcf TRISC,0 ; make IO Pin C0 an output
banksel LATC ; select bank2
clrf LATC ; init the LATCH by turning off everything
bsf LATC,0 ; turn on LED C0 (DS1)
goto $ ; sit here forever!
end
;

However, if I just use their example for tutorial 2:
bsf LATC, 0 ; turn LED on
OndelayLoop:
decfsz Delay1,f ; Waste time.
bra OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loops = 768
instructions
decfsz Delay2,f ; The outer loop takes an additional 3 instructions per lap * 256 loops
bra OndelayLoop ; (768+3) * 256 = 197376 instructions / 125K instructions per second =
1.579 ;sec.
bcf PORTC,0 ; Turn off LED C0 - NOTE: do not need to switch banks with 'banksel'
since ;bank0 is still selected
OffDelayLoop:
decfsz Delay1,f ; same delay as above
bra OffDelayLoop
decfsz Delay2,f
bra OffDelayLoop
bra MainLoop ; Do it again...

Nothing happens, am I doing something wrong?


 

MaxHeadRoom

Joined Jul 18, 2013
28,617
I haven't gone through all your code, but it seems you may be using some 16F code for a tutorial?
Bank switching is not needed in the higher end Pic's.
You need to convert to the instruction set for the Dsp or 18F you are using.
Max.
 

Thread Starter

MstrKurt

Joined Oct 26, 2013
18
How would I go about converting to the instruction for the 18F?

I'm learning on an 18F and then moving to a dsPIC33 when I am familiar with assembly.
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
You can take out the Banksel instructions, also there are some better ways to address data and prom memory in the 18F's etc.
Also Print out the instruction set for each and compare differences.
I see that there are a few copies of the Huang book on Abebooks clearance house fairly cheap.
Max.
 

Thread Starter

MstrKurt

Joined Oct 26, 2013
18
I have printed out the instruction set for the 18F's. But still have no progress with tutorial 2.

I don't understand some of the instructions used.
I understand bcf, bsf, clrf.

But decfsz movlw, movwf, osccon, and bra I have no idea?.

I'm more familiar with C than I am assembly but It's preferred to do this project in assembly according to my university.
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
But decfsz movlw, movwf, osccon, and bra I have no idea?.

.
I suggest keeping the particular pic PDF manual parked and pull it up and do a search in the document for the particular command etc.
Some are almost self descriptive.
The decfsz is decrement the file that follows and skip the next instruction if the file contents has reached zero . A file being a location in data memory previously assigned.
movlw = move a literal 8 bit expression into the WREG register.
movwf = is move the contents of WREG to the file that follows.
osconn = is an internal register, you will find it referenced in the .inc file
each bit conforms to a setting of the internal clock function.
again, a search in the PIC manual will show you the definition of each bit of the register.
bra = is an unconditional branch or jump to the label assigned by the program author e.g. bra WaitHere.
One of the instructions in the 18f etc is you can use instead of moving a byte into the WREG first is movff, movff test1,test2
Max.
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,159
decfsz -- decrement a file register, and skip the next instruction if the result is zero. The next instruction would typically be a 'goto' instruction that takes you back to the 'top of the loop'
movlw -- move a literal (aka constant) value contained in the instruction to the W register. The W register, as you know is the implied 'second' operand for most logical and arithmetic instructions.
movwf -- moves the contents of the W register to some other file register.
bra -- branch always. This is like a goto in that it always takes the branch, but the range is restricted to some number of words forward or backward from the current PC (program counter)
I didn't think osccon was an instruction , but rather a file register that controls the oscillator, but I could be wrong. I'm not as familiar with the 18F as the 16F.

What you need to do is locate an Instruction Set Reference. This document will explain each instruction in both words and shorthand symbols. Read the text on the subtract instructions very carefully. They subtract a file register from a constant which is counter intuitive with respect to most other processor architectures.
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
I didn't think osccon was an instruction , but rather a file register that controls the oscillator, but I could be wrong. I'm not as familiar with the 18F as the 16F.

What you need to do is locate an Instruction Set Reference. This document will explain each instruction in both words and shorthand symbols. .
OSCCON is a register not an instruction.

The Instruction definition is in all PicMicro manuals, including definition of all the registers.
Max.
 

Thread Starter

MstrKurt

Joined Oct 26, 2013
18
Thanks for the replies guys, I have read the manual and I'm getting an understanding slowly.

There is one thing I'm unsure with though, take for example:

decfsz delay1,f

From what I've learned here: decrement file skip if zero. File I'm decrementing is delay1? right?

But what is 'f'? and what value is delay1 to begin with?

The only delay1 I can find in the code otherwise is:
CBLOCK 0x60 ; Sample GPR variable register allocations
delay1 ; user variable at address 0x60
delay2 ; user variable at address 0x61
MYVAR3 ; user variable at address 0x62
ENDC
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
The decfsz delay1, F
Indicates that after the decrement, the result is placed back in the file delay1.
If it was decfsz, W, the file delay1 would be decremented and the result placed in the WREG, not back in the file.
F is the default.
The contents of delay1 is whatever value has been assigned or loading into it previously.
Max.
 

Attachments

Last edited:

Markd77

Joined Sep 7, 2009
2,806
If a file like delay1 has never had anything loaded into it, as would be the case at the start of that program, it's value is unknown. Usually that's a bad idea, but in this case it just means the first delay might not be the same length as all the others following it.
I've looked at the file contents at startup and most of the files contain 0xFF but some are different, usually most of the bits are "1" but one or two are "0"s.
Note that MPLAB simulator uses 0 for the default value, so if you forget to initialize variables, it might work fine in the simulator but not when burned to a chip (or even the other way round).
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
The Book I quoted in post #4 is fairly good, the author is Dr Huang and teaches computer science at Minnesota state Univ.
It has a chapter for each module of the 18F series, complete with exercises at the end of each chapter.
I have it in PDF or it is available used at AbeBooks from a few sources. ISBN 1-4018-3967-3.
The Picmicro site also has individual App notes on each module.
Max.
 

atferrari

Joined Jan 6, 2004
4,764
I'm learning on an 18F and then moving to a dsPIC33 when I am familiar with assembly.
Thinking ahead, sorry to tell you that the instruction sets are completely different.

Maybe, you could go straight to a demoboard with a PIC from the league you are interested in.

While the essential is still there, you need to get used to a new set of instructions, a hurdle you could avoid before starting. Wasting time is a concern, at least to me.

Good luck.
 
Top