Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Question about assembly code

Status
Not open for further replies.

daredavel

New Member
hello guys! Can anyone tell me about the RAM_START codes? What is the operation RAM_START+1 to 4?? RAM_START operation starts at 0x0c? is that correct? :confused: Sorry guys..i'm new at assembly.. Thanks guys!!

Code:
; RAM registers
ram_start	EQU 0x0c
dcnt0		EQU ram_start+1 ; delay counter 0
dcnt1		EQU ram_start+2 ; delay counter 1
dcnt2		EQU ram_start+3 ; delay counter 2
 
hello guys! Can anyone tell me about the RAM_START codes? What is the operation RAM_START+1 to 4?? RAM_START operation starts at 0x0c? is that correct? :confused: Sorry guys..i'm new at assembly.. Thanks guys!!

Code:
; RAM registers
ram_start	EQU 0x0c
dcnt0		EQU ram_start+1 ; delay counter 0
dcnt1		EQU ram_start+2 ; delay counter 1
dcnt2		EQU ram_start+3 ; delay counter 2

hi,
I guess a 16F84 PIC.?

Look at this clip from the datasheet, you will see that 0x0c is the start of the user RAM/Register memory block.
AAesp04..gif
 
Last edited:
what this is doing is defining the ram locations for dcnt0, dcnt1, dcnt2, etc...
RAM_START is 0x0c, therefore, RAM_START+1 is 0x0d... so anytime you use dcnt0, it will use RAM location 0x0d, and 0x0e for dcnt1, etc...

they are floating their declarations instead of using absolutes because if they port this to another micro, that has a RAM that starts at 0x60, then they only have to change one definition, RAM_START, and all the others will be automatically redefined. If he'd used absolutes (dcnt0 = 0x0d) then he'd have to change all his variable declarations as well.
 
Last edited:
what this is doing is defining the ram locations for dcnt0, dcnt1, dcnt2, etc...
RAM_START is 0x0c, therefore, RAM_START+1 is 0x0d... so anytime you use dcnt0, it will use RAM location 0x0d, and 0x0e for dcnt1, etc...

they are floating their declarations instead of using absolutes because if they port this to another micro, that has a RAM that starts at 0x60, then they only have to change one definition, RAM_START, and all the others will be automatically redefined. If he'd used absolutes (dcnt0 = 0x0d) then he'd have to change all his variable declarations as well.

I've no idea what 'floating' means in this context?.

But a far better way is to use Cblock.
 
I've no idea what 'floating' means in this context?.

But a far better way is to use Cblock.

'floating' means not absolutely nailed down, like the sentence says... they are indirectly defining them. Same thing your assembler does to modules... it assigns a relative address to all the 'labels', relative to the start of the code, then when you link it to your other code modules and locate it, it assigns real values. note, I did not say floating point.... that is a variable type.

"C Block"??? you were in prison???? :eek: don't just tell him, show an example of 'how you would use CBLOCK'... like he said, he's new to assembly.
 
Last edited:
Let's admit he could try to find out how to use CBLOCK.
 
yes, I wholeheartedly admit that. yes I do. Looks like he's learning assy language like I did in the early 80's, cut and paste king. Before that I programmed in machine code... on a 24 bit computer that spoke in octal and prepped and launched 16 nuclear tipped missiles from a submarine... talk about the ability to be dangerous....
 
Last edited:
"C Block"??? you were in prison???? :eek: don't just tell him, show an example of 'how you would use CBLOCK'... like he said, he's new to assembly.

People learn far more if they find such simple stuff themselves - examining PIC assembler code, or reading the helpfile, will show exactly what it is and how to use it. Checking my tutorials will also show what it's for - on the later tutorials.
 
Another question guys! is "#define" an assembly code? or C? here's an example guys..thank you!

Code:
#define		LED00			movlw 0						;1st Digit LED
#define		LED01			movlw 1						;2nd Digit LED
#define		LED02			movlw 3						;3rd Digit LED
#define		LED03			movlw 7
 
Another question guys! is "#define" an assembly code? or C? here's an example guys..thank you!

Code:
#define		LED00			movlw 0						;1st Digit LED
#define		LED01			movlw 1						;2nd Digit LED
#define		LED02			movlw 3						;3rd Digit LED
#define		LED03			movlw 7

Neither, it's an assembler directive - not code at all (think of it as a text 'search and replace').
 
Neither, it's an assembler directive - not code at all (think of it as a text 'search and replace').

Thank you sir Nigel! Does it mean that code1 somehow works the same as code2?

Code1:
Code:
dcnt0		EQU ram_start+1

Code2:
Code:
#define		LED00			movlw 0
 
In the respect that they are both essentially text search and replace, yes they do. The 'ram_start+1' is obviously evaluated before the search and replace is done.
 
oh..i see.. there for i conclude that, #define and EQU are the same..:) So i can make the code1 like this sir?

Code:
#define     dcnt0    ram_start+1
 
They are similar, but not identical - and like I said, CBlock is better for assigning GPR names. Here's an example of it in use:

Code:
		cblock	0x20			;start of general purpose registers
			count			;used in looping routines
			count1			;used in delay routine
			counta			;used in delay routine
			countb			;used in delay routine
			tmp1			;temporary storage
			tmp2
			templcd			;temp store for 4 bit mode
			templcd2	
		endc
 
yup! cblock is much easier to understand..:) But can i make it the other way around sir?

Code:
LED00		EQU 	movlw 0

What does readbuf_end do sir? do u have any notes regarding how it can be use, sir?

Code:
tmptr		EQU readbuf_end  
tmbyte		EQU readbuf_end+1

Btw, i found a very interesting way of incorporating keypad in asm..can you help me understand it sir? (i just started studying asm last week..there are alot of things that i don't know yet..and i'm glad that your helping me sir..:D)

Code:
keytable	
		movf keycode, W
		addwf PCL, F
		dt 0x60
		dt "123a"
		dt "456b"
		dt "789c"
		dt "*0#d"

keyscan		
		clrf keycode
		movlw 4
		movwf rowcnt

		movlw 0xfe
		tris PORTA 

rowscan		movlw 0xa0
		call udelay
		swapf PORTB, W
		movwf colstatus

		movlw 4
		movwf colcnt

colscan		incf keycode, F
		rrf colstatus, F
		btfss STATUS, C
		goto keytable

		decfsz colcnt, F
		goto colscan

		bsf STATUS, C

		bsf STATUS, RP0
		rlf TRISA, F 
		bcf STATUS, RP0

		decfsz rowcnt, F
		goto rowscan
		retlw 0
 
daredavel,

You should probably start here: mikroElektronika : books : PIC microcontrollers

It's a good introduction to programming in assembly for PICs. They even have all of the commands defined. So if you want to know what "#define" or "EQU" means...yep, they have it.

Moderator: Can you change the link in the Sticky to Mikro's new website? The above link replaces the one in the Sticky right below Nigel's.
 
debounce delay

i'm trying to play with the LEDs, by incrementing and decrementing them.. problem is, if i push the up switch(inc) just once, the 2 LEDs are lit instead of just one. I've heard about debouce delay but i don't know how to corporate it with my work.. the LEDs also blink..

here's my increment code:
Code:
;-----COUNT UP SWITCH---------------


Up_Switch
	Delay4
	btfsc	PORTA, 0
	goto	Exit1		
	
	movf	COUNT, W
	xorlw	12
	btfsc	STATUS, 2
	goto	Exit1
	incf	COUNT

Code:
Delay4
	movlw	1
	movwf	COUNT5


If i change the Delay4 value, the delay of the LED to blink is also affected..because i also use the Delay4 as a delay for may led.. I just wanted to try the debounce delay..:D Pls teach me how sir..:)
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top