On Mar 30, 2013, at 1:37 PM, [email protected] wrote:
> can i program msp430 in assembler with mspgcc ? How to ?
Sure. Name your file "program.S", and assemble using
msp430-gcc program.S
The .S extension tells gcc that the file is assembler, with preprocessing.
Be aware that the gnu assembler (known as "gas") does not have the same syntax
as the TI assembler.
Here's some MSP430 code written in the gnu assembler:
.macro entry f
.section .text.\f, "x"
.global \f
\f:
.endm
entry _getportpin
;;; Given a pin# as the first argument in a C function (in R15),
;;; convert this to the port address base in R15 and a bit in R13.
;;; return with Z set if the translation is bad.
mov.b r15, r13 ; get pin
mov.b p2port(r13),r15 ; get port based on pin (extend to word.)
mov.b p2bit(r13),r13 ; get bit
tst r15 ; see if it's valid; leave Z set if not.
ret
;;; pin# to port address translation table (stored in flash)
;;; In the current tables, pin#'s are based on the individual chip pins,
;;; so the first usable "pin" is "2"
p2port: .byte 0,0 ;0 not used. Pin 1 = Vdd
.byte 0x20, 0x20, 0x20, 0x20 , 0x20, 0x20, 0x20, 0x20 ;pin 2-9
.byte 0,0 ; pin 10 = RST, pin 11=TEST
.byte 0x28, 0x28 ; pin 12, 13
.byte 0 ; pin 14 = VSS
;;; pin# to bit (within a port) translation table.
p2bit: .byte 0,0
.byte 1,2,4,8, 16,32,64,128
.byte 0,0
.byte 128,64
.byte 0
;;; _digitalWrite(int pin, int value)
;;; actual code to implement the digitalWrite Arduino function (if it
;;; can't be implemented faster inline for the case where args are constant.)
;;; Write a digital value (zero or non-zero) to a particlar pin,
;;; assuming the pin is already set up properly as an output.
entry _digitalWrite ; (uint8_t pin , uint8_t val)
call #_getportpin ;get portbase, bit to r15, r13
jz dwret ;errorn
inc r15 ; adjust to xxOUT
tst.b r14 ;check value
jnz dw_nz
bic.b r13,0(r15)
ret
dw_nz:
bis.b r13,0(r15)
dwret: ret
;;; int _digitalRead(int pin)
;;; actual code to implement the digitalRead Arduino function (if it
;;; can't be implemented faster inline for the case where args are constant.)
;;; return 0 if the pin input is low, 1 if it is high.
entry _digitalRead
call #_getportpin ;get portbase, bit to r15, r13
jz drret ;digital read of invalid pin is 0
mov.b @r15, r15 ;read port (offset from base is 0 for IN)
and.b r13, r15 ;test bit
jz drret ; zero. retval in r15 is also conveniently zero
mov.b #1, r15
drret: ret
------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete
for recognition, cash, and the chance to get your game on Steam.
$5K grand prize plus 10 genre and skill prizes. Submit your demo
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users