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.

make assembly more simple

Status
Not open for further replies.

auri_z

New Member
use assembly for program microcontroller (PIC!6F877A) always same code repeating. how to write code more simple.

for example
Code:
    cblock    0x26
                temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9
                temp10,temp11,temp12,temp13,temp14,temp15,temp16,temp17
                temp18,temp19,temp20,temp21,temp22,temp23,temp24,temp25
                temp26,temp27,temp28,temp29,temp30,temp31,temp32,temp33
                temp34,temp35,temp36,temp37,temp38,temp39,temp40,temp41
                temp42,temp43,temp44,temp45,temp46,temp47,temp48,temp49
                temp50,temp51,temp52,temp53,temp54,temp55,temp56,temp57
                temp58,temp59,temp60,temp61,temp62,temp63,temp64,temp65
                temp66,temp67,temp68,temp69,temp70,temp71,temp72,temp73
            endc

can code above make more simple like:

Code:
cblock    0x26
                temp1,temp2,temp3...temp73

in my program also use same repeating code send data to PORTD, like

Code:
        movf        temp1,0            
                 movwf      PORTD            
                 call          tunda
                 movf        temp2,0
                 movwf      PORTD
                 call        tunda
                 ...
                 .....
                 movf      temp73,0
                  mvwf    PORTD
                  call       tunda

code above if write less efisien, how to make code more simple.
like in C can write

for temp=1;temp<73;temp++
movf temp
movwf PORTD
call tunda
 
The motivation for creating the C-programming language was to make "assembly more simple". I believe that C (with modern compilers) is more efficient than assembly written by mediocre programmer.
 
it's true C more simple than assembly, but my program was assembly. my instructor at school assign to make my program more simple in writing.
my code just repeating same code, i think there is away make my program more simple but i don,t know.
maybe someone with more exprience know what i don't know.

thnk
 
it's true C more simple than assembly, but my program was assembly. my instructor at school assign to make my program more simple in writing.
my code just repeating same code, i think there is away make my program more simple but i don,t know.
maybe someone with more exprience know what i don't know.

thnk

hi,
If your program code has the same block of code many times, consider writing a MACRO for that block.
NOTE: it will not make the assembled hex file any smaller but it will make writing the code text easier and the listing shorter.
 
Ok, sorry I miss-understood your question. It seems that you need to learn how to write arrays (tables) and program loops etc. in assembly. I hope someone here can give you good advice. I use assembly only in critical places of my C-programs.
 
Ok, sorry I miss-understood your question. It seems that you need to learn how to write arrays (tables) and program loops etc. in assembly. I hope someone here can give you good advice. I use assembly only in critical places of my C-programs.

i also think array or indexing can make simple, but i don't know how to use array or indexing in assembly . i now try to undestand it's. so far not found yet good references or good sample.
 
i also think array or indexing can make simple, but i don't know how to use array or indexing in assembly . i now try to undestand it's. so far not found yet good references or good sample.

hi,
Look at page #10 of this pdf..

Also this tutorial link should help you.
Elmer 160 -* Course Lessons
 

Attachments

  • PIC_Base_A_11.pdf
    321.5 KB · Views: 490
You can use indirect addressing,
Code:
		movlw	temp1
		movwf	FSR
Loop		movf	INDF,w            
		movwf	PORTD            
		call	tunda
		incf	FSR,f
		movfw	FSR
		xorlw	temp1+73
		btfss	STATUS,Z
		goto	loop

Mike.
 
I agree. Define the array like this;
Code:
        cblock  0x26
temp:73                         ; unsigned char temp[73]
        endc
Then access each array element directly in the operand like the example below or indirectly as per Mike's (Pommie's) example;
Code:
        movf    temp+d'0'       ; WREG = temp[0]
...
        movf    temp+d'22'      ; WREG = temp[22]
        movwf   temp+d'72'      ; save to temp[72]  // last array element
 
thank to all..
today i can make my program more simple and short.
my code after using indirect addressing just 11 line for display data to PORTD and clear just 10 line, original 216 and 72

Code:
  movlw     temp+d'0'        ; first array
            movwf    FSR            
Loop      movf      INDF,w            ;move content register 
            movwf    PORTD            
            call        tunda
            incf        FSR,f
            movf      FSR,w
            movwf    test     
            xorlw      temp+d'72'
            btfss      STATUS,Z
            goto       Loop
            return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top