0% found this document useful (0 votes)
37 views1 page

Basic Pic Book Preview03

Using high-level programming languages like Basic has advantages over assembly language for PIC microcontrollers. The compiler automatically handles complex operations like multiplication by breaking them down into simpler additions or instructions. This avoids having to deal with the lack of instructions in RISC architectures yourself. For example, in Basic you can simply write "a*b" instead of implementing multiplication with repeated additions in assembly. The same Basic program that turns on and off the ports of a PIC microcontroller is shown compiled to the equivalent assembly code.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views1 page

Basic Pic Book Preview03

Using high-level programming languages like Basic has advantages over assembly language for PIC microcontrollers. The compiler automatically handles complex operations like multiplication by breaking them down into simpler additions or instructions. This avoids having to deal with the lack of instructions in RISC architectures yourself. For example, in Basic you can simply write "a*b" instead of implementing multiplication with repeated additions in assembly. The same Basic program that turns on and off the ports of a PIC microcontroller is shown compiled to the equivalent assembly code.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ADVANTAGES OF HIGH-LEVEL PROGRAMMING LANGUAGES

If you have any experience in writing programs for PIC microcontrollers in assembly language, then you are probably familiar with the other side of the medal of RISC architecture - the lack of instructions. For example, there is no appropriate instruction for multiplying two numbers. Of course, there is a way to solve this issue owing to mathematics which enables you to perform complex operations by breaking them into a number of simple ones. Accordingly, multiplication can be easily substituted by successive addition (a x b = a + a + a + ... + a). And here we are, just at the beginning of a very long story... Still there is no reason to be worried about as far as you use one of the high-level programming languages, such as Basic, as the compiler will automatically find a solution to these and similar issues. Simply write a*b.
BSF BCF CLRF L__main2: BCF CLRF ' Configure pins as outputs MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF L__main6: DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO NOP NOP MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF L__main7: DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO NOP NOP GOTO 11 R11 38 R12 93 R13 R13, 1 L__main6 R12, 1 L__main6 R11, 1 L__main6 STATUS, 5 STATUS, 6 TRISA

2
Programming Microcontrollers s Programming Languages

main: TRISA = 0x00 While TRUE PORTA = 0x00 Delay_ms(1000) PORTA = 0xFF Delay_ms(1000) wend end.

STATUS, 5 PORTA

' ' ' '

Turn PORTA LEDs OFF 1 second delay Turn PORTA LEDs ON 1 second delay

' Endless loop

Program written in Basic

255 PORTA 11 R11 38 R12 93 R13 R13, 1 L__main7 R12, 1 L__main7 R11, 1 L__main7

L__main2 ' Endless loop $+0

The same program compiled into assembly code. As can be seen, each Basic command is broken into several assembly instructions during the process of compiling.

wend GOTO

PIC

MICROCONTROLLERS

PROGRAMMING IN

BASIC

55

You might also like