Assembler code...

jc173

Member
Guys,


I have been reading a book on Assmebler code in order to programme a blank chip for a bit of fun to show off in my design folio for college (as we have a programmer that couldbe used) I have read a book on Assembler but it's old and it's not clear

Does anyone know of any good tutorials on the web??



TIA


James
 

eclectic

Moderator
James.

I don't know if this might help, but

Programming Editor >> Help >> Assembler Datasheets.

then try the first four options.


e
 

Attachments

ylp88

Senior Member
My first tutorial into assembler programming PIC chips came from here:

http://www.mstracey.btinternet.co.uk/pictutorial/picmain.htm

I found it easy to follow and simple. It doesn't cover any tricky or complicated stuff (as far as I recall... it's been years!) but it gives a really good foundation as to the simple commands used to perform basic operations which ultimately allow you to use more complicated peripherals.

ylp88
 

jglenn

Senior Member
It is fun to just get an evaluation board, write some code, assemble it, download, and see what happens, just like with a PICAXE. Here is a delay routine I use that will run on about any pic, only takes 2 registers, sometimes you have to reassign them for different chips. Before you call it, set the W register to 00-FF, each count is 4mS when running at 4MHz. It takes 1uS to execute each instruction, the loop is tuned with NOPs. The incfsz instruction increments a file, then skips the next instruction if the result is zero. A quick test of a variable. But assembler overall is harder than Basic, due to having to worry about a bunch of arcane details, often. Instead of a simple a/d command, you may have 20 or 30 lines of code just to run the port. :(

movwf means move the file 21h into the W register. W means working reg, a scratchpad. Files = registers, interchangeable.


dly............movwf...21h
................clrf.......22h
dy.............clrwdt
................nop
................nop
................nop
................nop
................nop
................nop
................nop
................nop
................nop
................nop
................nop
................nop
................incfsz...22h
................jmp......dy
................decfsz..21h
................jmp......dy
................ret
 
Last edited:

lbenson

Senior Member
jglenn--to retain your spacing, edit your post and surround the code with [code]...[/code]
 

RobertN

Member
Try the first four options

eclectic,

Would like to see the first four options. How do you get to them? The attachment does not expand. Can you provide the URL for this.
 

eclectic

Moderator
eclectic,

Would like to see the first four options. How do you get to them? The attachment does not expand. Can you provide the URL for this.
The attachment is a screen-capture.

Make sure that you have PE v 5.2.2 loaded and running,
then follow the steps that I outlined in the posting.

Programming Editor >> Help >> Assembler Datasheets.

e
 

lbenson

Senior Member
Replacing "." with space and enclosing with [code]...[/code]

Code:
dly            movwf   21h
                clrf       22h
dy             clrwdt
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                incfsz   22h
                jmp      dy
                decfsz  21h
                jmp      dy
                ret
 

tiscando

Senior Member
Hi,

I just want to check with assembler code stuff that have not been referenced in the assembler manuals. (PE 5.2.6)

Are symbol definitions e.g. INTCON, PIR1 really case sensitive?

How do I type in decimal numbers, binary numbers, and hex numbers?
I see numbers like
Code:
B'10000110'
d'04'
h'20'
H'000C'
H'0081'
H'008D'
in the numbers prefixed H, the hex letter digits dont show the number colour like the other digits do.

Is that how I am supposed to enter numbers into e.g. for the k value in commands like 'movlw'?


Secondly, in the PIC16F819 manual at section 3.3, the example code 3-1 has "BANKSEL EEADR" at the start, where BANKSEL appears pink. Is this really valid?

Thirdly, PE hasn't included assembler templates for the PIC16F87/88 and for the PIC16F88x family yet.

Thanks, TC

edit: currently, PE doesn't seem to support filenames including it's path that is longer than about 62 chars, so I can't put assembler files in
C:\Users\Toby\Backup of Toby NANO\PICAXE files\assembler progs (where Backup of Toby NANO is synchronized with my flash drive).

I would suggest PE should fit file names into the window bar like this:
C:\Users\Tob...assembler progs\prog1.bas (where the bit after the ... only starts to colapse if the bit before ... has collaped all the way down)
Or like this:
C:\User...E files\assembler progs\prog1.bas (where the bit before ... always shows C:\ and 4 more chars of the start of the path)
Rather than just:
C:\Users\Toby\Backup of Toby NANO\PI...
so that I can't see the actual file.

(well, I'm not sure if this could be done on the name header in sub-windows inside the PE window - probably easier for it to just show the filename, and have an option to just show the filename, or show the full path of the file.)
 
Last edited:

hippy

Ex-Staff (retired)
Are symbol definitions e.g. INTCON, PIR1 really case sensitive?

Yes.

How do I type in decimal numbers, binary numbers, and hex numbers?

As shown, and you can specify the RADIX directive to set decimal by default and specify hexadecimal with a 0x prefix.

in the numbers prefixed H, the hex letter digits dont show the number colour like the other digits do.

That's a limitation of the Programming Editor expecting numbers to be in PICAXE format for colouring. Use decimals and 0x for hex prefixes and colours should be as expected.

Is that how I am supposed to enter numbers into e.g. for the k value in commands like 'movlw'?

Yes.

BANKSEL appears pink. Is this really valid?

It is valid.

PE hasn't included assembler templates for the PIC16F87/88 and for the PIC16F88x family yet.

Correct.

PE doesn't seem to support filenames including it's path that is longer than about 62 chars

That's a limitation of the Microchip Assembler. PE itself does support filenames longer than 62 characters.
 

tiscando

Senior Member
I see. :cool:

So how does BANKSEL work, even though it's not in the command set?

What about the prefix for binary numbers in assembler code mode? %10000110? or is there only B'10000110'?

edit:
the manual said:
To convert BASIC to assembler, the programmer needs to be plugged in.
Does it mean there is a PIC with a program that also converts BASIC to assembler?
 
Last edited:

hippy

Ex-Staff (retired)
The Microchip MPASM Assembler user manual is the best source of explanation for MPASM directives ...

ww1.microchip.com/downloads/en/DeviceDoc/33014J.pdf

BANKSEL configures the required RPx bits ready for an access into an SFR bank other than the bank currently selected.

I believe the only format for binary numbers is B'xxxx' but the above document may say otherwise.

That message applies to Convert BASIC to Assembler function which is made available when the BAS800 has been purchased and is connected. Programming Editor menu options Help -> Assembler Datasheets will give further details.
 

tiscando

Senior Member
MPASM manual

Thank you for your information.

Maybe the MPASM assembler user manual should be included in the help in PE as "advanced assembler information". Thank you for finding this as it would answer more questions. ;)
 

westaust55

Moderator
eclectic,

Would like to see the first four options. How do you get to them? The attachment does not expand. Can you provide the URL for this.
Also works okay from PE V5.2.5 (did not try in 5.2.6 tonight)

Seems like there is a need for some to read the relevant PIC datasheet:eek:
to undertsand how som of the SFR's are used
 
Last edited:
Top