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.

Mikropascal and their assembly

Status
Not open for further replies.

Eric Koh

New Member
Hi guys.

I just started using their demo version of their PIC IDE + compiler and being new to uC programmming...I find that their asm generated appears to be huge.........any comments?

I just wanted the PORTB to output AAH delay 1 sec and 55H and delay 1 sec.....

Pascal Version
program Led_blinking;
begin
TRISB := 0; // configure pins of portb as output
repeat // beginning of a repeat loop
begin
PORTB := $AA; // turn ON diodes on portb
delay_ms(1000); // wait for 1 second
PORTB := $55;
delay_ms(1000); // wait for 1 second

end;
until 0 = 1; // endless loop (as this condition is never satisfied)
end.

Assembly Version [Generated by Mikropascal Compiler] GOTO main
;--- procedure main ---
main:
CLRF TRISB,0
L_Led_blinking_0:
MOVLW 170
MOVWF PORTB,0
MOVLW 6
MOVWF STACK_1,0
MOVLW 255
MOVWF STACK_2,0
MOVLW 255
MOVWF STACK_3,0
DECFSZ STACK_1,F,0
GOTO $+2
GOTO $+8
DECFSZ STACK_2,F,0
GOTO $+2
GOTO $+4
DECFSZ STACK_3,F,0
GOTO $-1
GOTO $-5
GOTO $-9
MOVLW 26
MOVWF STACK_1,0
MOVLW 255
MOVWF STACK_2,0
DECFSZ STACK_1,F,0
GOTO $+2
GOTO $+4
DECFSZ STACK_2,F,0
GOTO $-1
GOTO $-5
MOVLW 66
MOVWF STACK_1,0
DECFSZ STACK_1,F,0
GOTO $-1
MOVLW 85
MOVWF PORTB,0
MOVLW 6
MOVWF STACK_1,0
MOVLW 255
MOVWF STACK_2,0
MOVLW 255
MOVWF STACK_3,0
DECFSZ STACK_1,F,0
GOTO $+2
GOTO $+8
DECFSZ STACK_2,F,0
GOTO $+2
GOTO $+4
DECFSZ STACK_3,F,0
GOTO $-1
GOTO $-5
GOTO $-9
MOVLW 26
MOVWF STACK_1,0
MOVLW 255
MOVWF STACK_2,0
DECFSZ STACK_1,F,0
GOTO $+2
GOTO $+4
DECFSZ STACK_2,F,0
GOTO $-1
GOTO $-5
MOVLW 66
MOVWF STACK_1,0
DECFSZ STACK_1,F,0
GOTO $-1
GOTO L_Led_blinking_0
L_Led_blinking_1:
GOTO $
;---endproc---
 
your compiler puts the delay code inline wich makes your asm code huge... Better compilers would put it ina subroutine...

still, I haven't seen any compiler for a pic wich generates efficient code, all of them waste memory...
Can't live with that? program in asm ... :?
 
Hahaha...took out the delay..and guess what...

definitely much smaller now....now that looks pretty alrite now..

kind of a bit silly of them to do that though....I think I'm gonna wait a while before I get the licensed version of it though...looks like they havent optimized the compiler properly..

I really suck at doing assembly...and recommendations on a IDE + Compiler in C for PIC18 and PIC16 at reasonable cost?

Pascal Version
program Led_blinking;
begin
TRISB := 0; // configure pins of portb as output
repeat // beginning of a repeat loop
begin
PORTB := $AA; // turn ON diodes on portb
//delay_ms(1000); // wait for 1 second
PORTB := $55;
//delay_ms(1000); // wait for 1 second

end;
until 0 = 1; // endless loop (as this condition is never satisfied)
end.

ASM Version
GOTO main
;--- procedure main ---
main:
CLRF TRISB,0
L_Led_blinking_0:
MOVLW 170
MOVWF PORTB,0
MOVLW 85
MOVWF PORTB,0
GOTO L_Led_blinking_0
L_Led_blinking_1:
GOTO $
;---endproc---[/b]
 
Eric Koh said:
I really suck at doing assembly...and recommendations on a IDE + Compiler in C for PIC18 and PIC16 at reasonable cost?

microchips MPLAB IDE (free) is a nice IDE with build in simulator and lots of toys, it supports a plug in C compiler of microchip themselves (MPLAB C18 - not free) for PIC18 chips, wich is probabely one of the best C complilers for pic's 18 series

**broken link removed**

For 16F series i sometimes use c2c pic c (if its a very small program then memory waste doesnt matter)
**broken link removed**

But you should definately study assembler as well. when writing bigger projects you will run into problems if you don't know how the assembly on the background works...
 
Exo said:
your compiler puts the delay code inline wich makes your asm code huge... Better compilers would put it ina subroutine...

Yes, you would expect it as a subroutine, but with Pascal you can define Functions and Procedures (presumably this version allows these?), you could write a Procedure which calls the delay_ms() routine.

still, I haven't seen any compiler for a pic wich generates efficient code, all of them waste memory...

Bound to, that's the way they work, my BASIC one is probably better than most, but all variables are 16 bit - which makes things slightly slower, but cuts down on the size of the code. One day it might be ready for release!.

Can't live with that? program in asm ... :?

Yes, you really need to anyway, even if you mainly use a high level language.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top