Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembly language syntax

Status
Not open for further replies.

Tico1

Programmer
Aug 10, 2006
3
US
Hi all, I am traying to write my first program using assembly. I have trouble understanding many things. Looking at the samples that I have, assembly samples for PIC16F87 I can see used EQU or equ or res as part of declatation or seems to be a declaration, and I am not sure I understand 100% what that means.

I forgat to say that I am a C# programmer as well as C/C++.
One more question: what kind of label do I have to use for an ISR routine. With other words how do I indicate to assembler that the following code has to be executed on interrupt. There is a good book that could have those answers or there is somone that could halp me with that??? your answer will be greatly appreciated....thanks a lot.

 
equ" is an assembler directive that assigns values to labels.

For instance

Code:
fred equ 0x33

will give the label "fred" the value 0x33 (51 decimal).

There's a vast amount of data on the microchip site related to programming PICs (odd that).

I've used a couple of books.

The one I have to hand is "PIC Your personal Introductory Course" by John Morton.

The interrupt service routine is located at address 004h.

The pic jumps to address 4 when it receives an interrupt. It doesn't really need a label, but you can give it a label if you like.

If you look in the MPLAB code templates for the PIC you are using, there are get you started examples.

Hope that helps a little.
 
Thanks a lot...your answer actually triggered more questions, like: a label is a PC address??? and there is any difference between EQU or equ. I would ask dirrectly how I declare a variable and how I declare a constant??? is "res" used to declare a variable???? that's my conclusion just playing with MPLAB simulator.

Your answer will greatly appreciated....
 
There's no difference between "equ" and "EQU".

MPLAB somewhere in its setup has a tick box that turns on case sensitivity if it's a problem. It normally runs without.

In the code segment, a label like "FRED" is the address of an instruction.

Code:
     goto FRED

some other stuff in here

FRED  addlw 1    ;a comment comes after the ";"

"Variables" are declared in the data segment.

The PIC is a bit weird as ram is referred to as registers in the documentation.

The data segment contains "Special Purpose Registers" that include the working register W and peripheral control registers and "General Purpose Registers" which are essentially just ram. The addresses of these are given in the data sheet.

Code:
   list    p=16F84 ;select processor type
   radix   hex     ;define radix as hexadecimal

;----------------------------------------------------------
;	cpu equates (memory map)
; Special Function Register Addresses

INDF	equ 0x00     ;indirect addressing register
PCL	equ 0x02     ;lower program counter byte
FSR	equ 0x04     ;indirect memory address data pointer
portA	equ 0x05     ;port A address
portB	equ 0x06     ;port B address
trisb	equ 0x06     ;trisB address in register bank 1

status	equ 0x03     ;status register
RP0     equ 5        ;bit 5 of status register
RP1 	equ 6        ;bit 6 of status register

w       equ 0        ;w register


; General Purpose Register Addresses

Count1  equ 0x0d     ;pause routine inner loop counter
Count2	equ 0x0e     ;pause routine outer loop counter

;---------------------------------------------------------

; this is the program segment

   org 0x000 ;this sets the start address to 0x000

start        ;this label has the value 0x000
   movlw 10  ; put the value 0x10 into W

get_cnt      ;this label has the value 0x001

    addlw 1  ; add the literal value 1 to W

    goto get_cnt  ; repeat forever

Most of this sort of stuff is available on the web if you look for it.
 
Ok, all addvice so far is very much appreciated. I made progress actually, I have a source code done by somebody else and I am trying to understand. One of the questions is:

When an external interrupt occurs the PC is set to 0x04 for PIC16F87 and the execution starts there where normally all status is pushed in the stack the interapt is executed and before exiting the previous status is poped from stack. My confution starts from the fact that the ISR routine is called from the main and the debugger mode I can see the ISR routine being visited continuously and the INTF flag being checked. I expected that ISR is entered only when my PORTB0 goes low or hight depends how is set.

One other question is related to INTF which is used looks like it contains the bit number of TMR0IF in INTCON register. I tried to find a declaration of it and I did not find it in any asm or inc file. I found a lst file containg a declaration of INTF. The question is who did that? and what is the real meaning of it....


Your answer will be greatly appreciated....


Thank a lot
 
TMR0IF is found in the p16f87.inc file on my MPLAB 6.3 installation. (That's in the MCHIP_Tools folder).

It's in the section of the file marked "INTCON Bits".

If it wasn't defined somewhere it would generate an error.

If you are seeing interrupts "continuously", then I'd guess that the timer is generating regular interrupts, but that's only a guess...

Since the PIC16f87 has just the one interrupt vector, it can get a little busy in there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top