Last active
August 29, 2015 13:58
-
-
Save kizzlebot/10319270 to your computer and use it in GitHub Desktop.
addition working, Need LCD output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.cdecls C,LIST,"msp430g2553.h" | |
.text | |
.retain | |
.retainrefs | |
.sect ".sysmem" | |
arg .space 0x0000 | |
arg1 .space 0x0000 | |
arg2 .space 0x0000 | |
.sect ".const" | |
.text | |
.global _START | |
START mov.w #300h,SP | |
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL | |
SetupP1 bis.b #01h,&P1DIR | |
call #Init_UART | |
;***************************************************************** | |
MainLoop | |
;***************************************************************** | |
xor.b #01,&P1OUT | |
Wait mov.w #0A000h,R15 | |
_dec dec.w R15 | |
jnz _dec | |
;call #readTwoArgs4 | |
;call #CRLF | |
call #addition2 | |
;call #subtraction | |
;call #multiply | |
jmp MainLoop | |
;***************************************************************** | |
; ___ _ _ _ _ _ | |
; / _ \ (_)| | | | | | (_) | |
; / /_\ \ _ __ _ | |_ | |__ _ __ ___ ___ | |_ _ ___ | |
; | _ || '__|| || __|| '_ \ | '_ ` _ \ / _ \| __|| | / __| | |
; | | | || | | || |_ | | | || | | | | || __/| |_ | || (__ | |
; \_| |_/|_| |_| \__||_| |_||_| |_| |_| \___| \__||_| \___| | |
;***************************************************************** | |
multiply | |
;***************************************************************** | |
push.w R7 | |
push.w R6 | |
push.w R5 | |
push.w R4 | |
mov.w #0x0000, R7 ; Accumulate in R7 | |
call #readHex2 | |
mov.w R4, R5 | |
call #MULT | |
call #readHex2 | |
_bitByBit mov.w R5, R6 ; Move R5 to R6 and test R6 for 1 in lsb | |
and.w #0x0001, R6 | |
jz _nextIter | |
add.w R4, R7 | |
_nextIter call #shiftLeftW ; ShiftL R4 | |
mov.w R4, R6 ; Save R4 in R6 so I can shiftR R5 | |
mov.w R5, R4 ; Use R5 as argument to shiftR | |
call #shiftRightW ; ShiftR R5 | |
mov.w R4, R5 ; move result to r5 | |
mov.w R6, R4 ; move R4 back | |
cmp.w #0x0000, R5 ; When out R5 contains no 1's, we're done | |
jnz _bitByBit | |
call #EQUALS | |
mov.w R7, R4 | |
call #printVal4 | |
call #CRLF | |
pop.w R4 | |
pop.w R5 | |
pop.w R6 | |
pop.w R7 | |
ret | |
;---------------------------------------------------------------- | |
addition4 | |
;---------------------------------------------------------------- | |
push.w R4 | |
push.w R5 | |
push.w R6 | |
; Read first two hex digits | |
call #readHex4 | |
mov.b R4, R5 | |
call #PLUS | |
call #readHex4 | |
call #EQUALS | |
; Calculate the sum into R4 and print it | |
add.w R5,R4 | |
mov.w SR, R6 | |
call #printVal4 | |
call #CRLF | |
mov.w R6, R4 | |
call #Status | |
pop.w R6 | |
pop.w R5 | |
pop.w R4 | |
ret | |
;---------------------------------------------------------------- | |
addition2 | |
;---------------------------------------------------------------- | |
push.w R4 | |
push.w R5 | |
push.w R6 | |
; Read first two hex digits | |
call #readHex2 | |
mov.b R4, R5 | |
call #PLUS | |
call #readHex2 | |
call #EQUALS | |
; Calculate the sum into R4 and print it | |
add.w R5,R4 | |
mov.w SR, R6 | |
call #printVal4 | |
call #CRLF | |
mov.w R6, R4 | |
call #Status | |
pop.w R6 | |
pop.w R5 | |
pop.w R4 | |
ret | |
;---------------------------------------------------------------- | |
subtraction | |
;---------------------------------------------------------------- | |
push.w R4 | |
push.w R5 | |
push.w R6 | |
call #readHex2 | |
mov.b R4, R6 | |
call #MINUS | |
call #readHex2 | |
mov.b R4, R5 | |
mov.b R6, R4 | |
call #EQUALS | |
sub.w R5,R4 | |
jn _subNeg | |
jmp _printSub | |
_subNeg inv.w R4 | |
add.w #0x0001, R4 | |
call #NEGATIVE | |
_printSub call #printVal4 | |
call #CRLF | |
pop.w R6 | |
pop.w R5 | |
pop.w R4 | |
ret | |
;***************************************************************** | |
; ______ _ _ | |
; | ___ \ (_) | | | |
; | |_/ /_ __ _ _ __ | |_ | |
; | __/| '__|| || '_ \ | __| | |
; | | | | | || | | || |_ | |
; \_| |_| |_||_| |_| \__| | |
;***************************************************************** | |
;***************************************************************** | |
printVal4 | |
;***************************************************************** | |
push.w R4 | |
swpb R4 | |
and.w #0x00ff, R4 | |
call #printVal2 | |
pop.w R4 | |
push.w R4 | |
and.w #0x00ff, R4 | |
call #printVal2 | |
pop.w R4 | |
ret | |
;***************************************************************** | |
printVal2 | |
;***************************************************************** | |
push.w R4 ; R4: (0011 1110) | |
rra.b R4 ; R4: (0001 1111) | |
rra.b R4 ; R4: (1000 1111) | |
rra.b R4 ; R4: (1100 0111) | |
rra.b R4 ; R4: (1110 0011) | |
and.w #0x000F, R4 ; R4: (0000 0011) | |
call #printVal1 | |
pop.w R4 | |
push.w R4 | |
and.w #0x000F, R4 ; R4: (0000 1110) | |
call #printVal1 | |
pop.w R4 | |
ret | |
;***************************************************************** | |
printVal1 ; If R4 = 0x0A, will print 'A' to terminal | |
;***************************************************************** | |
cmp.b #0x0A, R4 | |
jl isNum | |
add.b #0x37, R4 | |
call #OUTA | |
sub.b #0x37, R4 | |
ret | |
isNum add.b #0x30, R4 | |
call #OUTA | |
sub.b #0x30, R4 | |
ret | |
;***************************************************************** | |
Status ; R4 Needs to contain SR | |
;***************************************************************** | |
push.w R4 | |
push.w R5 | |
push.w R6 | |
mov.w R4, R5 | |
mov.w R4, R6 | |
Carry mov.b #'C', R4 | |
call #OUTA | |
call #EQUALS | |
and.w #0x0001, R5 | |
jz _cZero | |
mov.w #0x1, R4 | |
call #printVal1 | |
call #SPACE | |
jmp ZeroStat | |
_cZero mov.w #0x0, R4 | |
call #printVal1 | |
call #SPACE | |
ZeroStat mov.w R6, R5 | |
mov.b #'Z', R4 | |
call #OUTA | |
call #EQUALS | |
and.w #0x0002, R5 | |
jz _zZero | |
mov.w #0x1, R4 | |
call #printVal1 | |
call #SPACE | |
jmp NegStat | |
_zZero mov.w #0x0, R4 | |
call #printVal1 | |
call #SPACE | |
NegStat mov.w R6, R5 | |
mov.b #'N', R4 | |
call #OUTA | |
call #EQUALS | |
and.w #0x0004, R5 | |
jz _nZero | |
mov.w #0x1, R4 | |
call #printVal1 | |
call #SPACE | |
jmp VStat | |
_nZero mov.w #0x0, R4 | |
call #printVal1 | |
call #SPACE | |
VStat mov.w R6,R5 | |
mov.b #'V', R4 | |
call #OUTA | |
call #EQUALS | |
and.w #0x0100, R5 | |
jz _vZero | |
mov.w #0x1, R4 | |
call #printVal1 | |
call #SPACE | |
jmp _StatFin | |
_vZero mov.w #0x0, R4 | |
call #printVal1 | |
call #SPACE | |
_StatFin call #CRLF | |
pop.w R6 | |
pop.w R5 | |
pop.w R4 | |
ret | |
;***************************************************************** | |
; ______ _ | |
; | ___ \ | | | |
; | |_/ / ___ __ _ __| | | |
; | / / _ \ / _` | / _` | | |
; | |\ \| __/| (_| || (_| | | |
; \_| \_|\___| \__,_| \__,_| | |
;***************************************************************** | |
;---------------------------------------------------------------- | |
readTwoArgs4 ; Returns two sets of 4 digit hex in R4 and R5 | |
;---------------------------------------------------------------- | |
push.w R6 | |
call #readHex4 | |
mov.w R4, R6 | |
call #SPACE | |
call #readHex4 | |
mov.w R4, R5 | |
mov.w R6, R4 | |
call #SPACE | |
pop.w R6 | |
ret | |
;---------------------------------------------------------------- | |
readHex4 | |
;---------------------------------------------------------------- | |
push.w R5 | |
mov.w #0x0000, R5 | |
call #readHex2 | |
mov.w R4,R5 | |
swpb R5 | |
call #readHex2 | |
and.w #0x00FF, R4 | |
xor.w R5, R4 | |
pop.w R5 | |
ret | |
;---------------------------------------------------------------- | |
readHex2 | |
;---------------------------------------------------------------- | |
push.w R5 | |
call #readHex | |
mov.b R4, R5 | |
and.w #0x00FF,R5 | |
rla.b R5 | |
rla.b R5 | |
rla.b R5 | |
rla.b R5 | |
call #readHex | |
and.w #0x00FF,R4 | |
xor.w R5, R4 | |
pop.w R5 | |
ret | |
;***************************************************************** | |
readHex ; Reads a asciiHex, prints it, converts it to the | |
; value it represents and returns | |
;***************************************************************** | |
call #INCHAR | |
call #validateAsciiHex | |
cmp.b #0x00, R4 | |
jz readHex | |
call #OUTA | |
call #asciiToVal | |
ret | |
;---------------------------------------------------------------- | |
validateAsciiHex ; Will put 0x00 into R4 if R4 isn't valid hex | |
; ascii range | |
;---------------------------------------------------------------- | |
; check for 0- | |
cmp.b #0x30,R4 ; R4 < 0 | |
jl invalid ; If less, read again | |
; check fo -9 | |
cmp.b #0x3A,R4 | |
jn verified | |
; check for ~A- | |
cmp.b #0x41,R4 ; 0x41 < R4 | |
jl invalid ; If less, read again | |
; check fo -F | |
cmp.b #0x47,R4 ; R4-0x47 < 0 | |
jn verified | |
; check for ~a- | |
cmp.b #0x61,R4 ; R4-0x2F > 0 | |
jl invalid ; If n set, jump to ret | |
; check fo ~-f | |
cmp.b #0x67,R4 | |
jn Cap | |
jmp invalid | |
Cap sub.b #0x20,R4 | |
verified ret | |
invalid mov.b #0x00, R4 | |
ret | |
;---------------------------------------------------------------- | |
asciiToVal ; Takes ascii byte in R4 and makes it into | |
; hexadecimal digit. R4 must be verified to | |
; be a valid g | |
;---------------------------------------------------------------- | |
and.w #0x00FF,R4 | |
cmp.b #0x41, R4 | |
jhs isChar | |
sub.b #0x30, R4 | |
jmp asciiToValFin | |
isChar sub.b #0x37, R4 | |
asciiToValFin ret | |
;---------------------------------------------------------------- | |
; _ _ _ | |
; | | | | | | | |
; | |_| | ___ | | _ __ ___ _ __ ___ | |
; | _ | / _ \| || '_ \ / _ \| '__|/ __| | |
; | | | || __/| || |_) || __/| | \__ \ | |
; \_| |_/ \___||_|| .__/ \___||_| |___/ | |
; | | | |
; |_| | |
;---------------------------------------------------------------- | |
;---------------------------------------------------------------- | |
shiftLeftW | |
;---------------------------------------------------------------- | |
rla.w R4 ; Move MSB to LSB | |
and.w #0xFFFE, R4 ; Zero out the LSB | |
ret | |
;---------------------------------------------------------------- | |
shiftRightW | |
;---------------------------------------------------------------- | |
rra.w R4 | |
and.w #0x7FFF, R4 | |
ret | |
;---------------------------------------------------------------- | |
; _____ _ _ | |
; / __ \| | | | | |
; | / \/| |__ __ _ _ __ __ _ ___ | |_ ___ _ __ ___ | |
; | | | '_ \ / _` || '__|/ _` | / __|| __|/ _ \| '__|/ __| | |
; | \__/\| | | || (_| || | | (_| || (__ | |_| __/| | \__ \ | |
; \____/|_| |_| \__,_||_| \__,_| \___| \__|\___||_| |___/ | |
;---------------------------------------------------------------- | |
;---------------------------------------------------------------- | |
CR | |
;---------------------------------------------------------------- | |
push.w R4 | |
mov.b #0x0D, R4 ; CR | |
call #OUTA | |
pop.w R4 | |
ret | |
;---------------------------------------------------------------- | |
LF | |
;---------------------------------------------------------------- | |
push.w R4 | |
mov.b #0x0A, R4 ; LF | |
call #OUTA | |
pop.w R4 | |
ret | |
;---------------------------------------------------------------- | |
NULL | |
;---------------------------------------------------------------- | |
push.w R4 | |
mov.b #0x00, R4 | |
call #OUTA | |
pop.w R4 | |
ret | |
;---------------------------------------------------------------- | |
CRLF | |
;---------------------------------------------------------------- | |
call #CR | |
call #LF | |
call #NULL | |
ret | |
;---------------------------------------------------------------- | |
SPACE | |
;---------------------------------------------------------------- | |
push.w R4 | |
mov.b #0x20, R4 ; SPACE | |
call #OUTA | |
pop.w R4 | |
ret | |
;--------------------------------------------------------------------------------------------------------- | |
PLUS | |
;--------------------------------------------------------------------------------------------------------- | |
call #SPACE | |
push R4 | |
mov.b #0x2B, R4 ; + | |
call #OUTA | |
pop R4 | |
call #SPACE | |
ret | |
;--------------------------------------------------------------------------------------------------------- | |
MINUS | |
;--------------------------------------------------------------------------------------------------------- | |
call #SPACE | |
push R4 | |
mov.b #0x2D, R4 ; - | |
call #OUTA | |
pop R4 | |
call #SPACE | |
ret | |
;--------------------------------------------------------------------------------------------------------- | |
EQUALS | |
;--------------------------------------------------------------------------------------------------------- | |
call #SPACE | |
push R4 | |
mov.b #0x3D, R4 ; = | |
call #OUTA | |
pop R4 | |
call #SPACE | |
ret | |
;--------------------------------------------------------------------------------------------------------- | |
MULT | |
;--------------------------------------------------------------------------------------------------------- | |
call #SPACE | |
push R4 | |
mov.b #0x2A, R4 ; = | |
call #OUTA | |
pop R4 | |
call #SPACE | |
ret | |
;--------------------------------------------------------------------------------------------------------- | |
NEGATIVE | |
;--------------------------------------------------------------------------------------------------------- | |
push R4 | |
mov.b #0x2D, R4 ; - | |
call #OUTA | |
pop R4 | |
ret | |
;---------------------------------------------------------------- | |
; _____ _ _ | |
; |_ _| (_)| | | |
; | | _ __ _ | |_ | |
; | | | '_ \ | || __| | |
; _| |_| | | || || |_ | |
; \___/|_| |_||_| \__| | |
;---------------------------------------------------------------- | |
;---------------------------------------------------------------- | |
OUTA | |
;---------------------------------------------------------------- | |
push R5 | |
lpa mov.b &IFG2,R5 | |
and.b #0x02,R5 | |
cmp.b #0x00,R5 | |
jz lpa | |
mov.b R4,&UCA0TXBUF | |
pop R5 | |
ret | |
;---------------------------------------------------------------- | |
INCHAR | |
;---------------------------------------------------------------- | |
push R5 | |
lpb mov.b &IFG2,R5 | |
and.b #0x01,R5 | |
cmp.b #0x00,R5 | |
jz lpb | |
mov.b &UCA0RXBUF,R4 | |
pop R5 | |
ret | |
;---------------------------------------------------------------- | |
Init_UART | |
;---------------------------------------------------------------- | |
mov.b &CALBC1_1MHZ, &BCSCTL1 | |
mov.b &CALDCO_1MHZ, &DCOCTL | |
mov.b #0x06,&P1SEL | |
mov.b #0x06,&P1SEL2 | |
mov.b #0x00,&UCA0CTL0 | |
mov.b #0x81,&UCA0CTL1 | |
mov.b #0x00,&UCA0BR1 | |
mov.b #0x68,&UCA0BR0 | |
mov.b #0x06,&UCA0MCTL | |
mov.b #0x00,&UCA0STAT | |
mov.b #0x80,&UCA0CTL1 | |
mov.b #0x00,&IE2 | |
ret | |
;---------------------------------------------------------------- | |
; Interrupt Vectors | |
;---------------------------------------------------------------- | |
.sect ".reset" ; MSP430 RESET Vector | |
.short START | |
.end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment