diff --git a/Example/Makefile b/Example/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..ab37f69e9c9eafd6ed3e69b9c1b17664bc75538e --- /dev/null +++ b/Example/Makefile @@ -0,0 +1,41 @@ +# Project name +SOURCE = main.c +ADDITIONAL = min.S +# Get base name so we can create .elf file +NAME = $(basename $(SOURCE)) +# MSP430 MCU to compile for +CPU = msp430g2553 +# Optimisation level +OPTIMIZATION = -O0 +# Extra variables +CFLAGS = -mmcu=$(CPU) $(OPTIMIZATION) -std=c99 -Wall -g -fomit-frame-pointer +# Libemb library link flags +LIBEMB = -lshell -lconio -lserial + +# Build and link executable +$(NAME).elf: $(SOURCE) $(ADDITIONAL) +ifeq (,$(findstring libemb,$(shell cat $(SOURCE)))) + msp430-gcc $(CFLAGS) -o $@ $(SOURCE) $(ADDITIONAL) +else + msp430-gcc $(CFLAGS) -o $@ $(SOURCE) $(ADDITIONAL) $(LIBEMB) +endif + msp430-objdump -D $(NAME).elf > $(NAME).hex + +# Flash to board with mspdebug +flash: $(NAME).elf + mspdebug rf2500 "prog $(NAME).elf" + +# Erase board +erase: + mspdebug rf2500 erase + +stuff: hworld.c + echo "I found hworld.c!" && cat hworld.c + +# Clean up temporary files +clean: + rm -f *.elf *.hex + +# Remote debug board +debug: $(NAME).elf + ( mspdebug rf2500 "gdb" 1>/dev/null & ); msp430-gdb $(NAME).elf -ex "target remote :2000" diff --git a/Example/main.c b/Example/main.c new file mode 100644 index 0000000000000000000000000000000000000000..307db17a887da91eb5459b9d5b0f6665fe669d53 --- /dev/null +++ b/Example/main.c @@ -0,0 +1,24 @@ +#include <msp430.h> +#include <libemb/serial/serial.h> +#include <libemb/conio/conio.h> + +int min(int, int); + +int main(void) +{ + WDTCTL = WDTPW | WDTHOLD; + BCSCTL1 = CALBC1_1MHZ; + DCOCTL = CALDCO_1MHZ; + + serial_init(9600); + + cio_printf("min(9, 2): %i\n\r", min(9, 2)); + cio_printf("min(1, 2): %i\n\r", min(1, 2)); + cio_printf("min(4, 4): %i\n\r", min(4, 4)); + cio_printf("min(-1, -2): %i\n\r", min(-1, -2)); + cio_printf("min(-1, 2): %i\n\r", min(-1, 2)); + + for(;;); + + return 0; +} diff --git a/min.S b/Example/min.S similarity index 100% rename from min.S rename to Example/min.S diff --git a/Makefile b/Makefile index ab37f69e9c9eafd6ed3e69b9c1b17664bc75538e..a5f2cbfcfefe5be9e2115575de32bfde80bb576d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Project name SOURCE = main.c -ADDITIONAL = min.S +ADDITIONAL = MyMult.S # Get base name so we can create .elf file NAME = $(basename $(SOURCE)) # MSP430 MCU to compile for diff --git a/MyMult.S b/MyMult.S new file mode 100644 index 0000000000000000000000000000000000000000..42ed3b57ad74b1d3802c563e5833c18f0746d17c --- /dev/null +++ b/MyMult.S @@ -0,0 +1,47 @@ +; ************************************************************************************************* +; CS2230, Assignment 5, Brandon Rodriguez +; +; Assembly Code for MyMult method. +; Performs multiplication via repeated addition. (Or at least attempts to) +; ************************************************************************************************* + + .file "MyMult.S" ; + .text ; Location of instructions. +.global MyMult ; Create global for linker/loader. + ; Essentially, allows Main.c to detect and read. + +; ------------------------------------------------------------------------------------------------- + +MyMult: ; Start of MyMult Function + ; Basically initialization. + + + MOV.w #0x00, R12 ; Clear R12 by setting value to 0. + MOV.w #0x00, R13 ; Clear R13 by setting value to 0. + JMP addLoop ; Start loop to "multiply" by adding. + +; ------------------------------------------------------------------------------------------------- + +addLoop: ; Start of AddLoop Function. + ; Essentially, this will loop through (times equal to R14). + ; For each loop, adds the value of R15 into R13. + ; When done, will place the "multiplied" value of R13 into R15. + + + ADD.w #0x01, R12 ; Add 1 to R12 for loop counter. + ADD.w R15, R13 ; Add R13 and R15. Value placed into R13. + CMP.w R12, R14 ; Compares R12 and R14. Should be equal if done simulationing mult. + JNE addLoop ; If not equal, go through loop again. Else, proceed. + + MOV.w R13, R15 + JMP endMyMult ; Done multiplying. End function and return. + +; ------------------------------------------------------------------------------------------------- + +endMyMult: ; Start of EndMyMult Function. + ; Return to main. + + + RET ; Return from function. + +; ------------------------------------------------------------------------------------------------- diff --git a/README b/README index 05096bf32cc1c0fbd5e5d37dd5952d7aa5bbda43..497d65a3a5ff952001d00f2446ccbe38edfa8533 100644 --- a/README +++ b/README @@ -17,10 +17,10 @@ NOTE: Anything after a ; on a line is a comment .file "min.S" <=== actually omittable .text <=== the program is built in 'sections' - <=== the text section is for RO instructions - .global min <== the label / location 'min' needs to be seen + <=== the text section is for RO instructions +.global min <== the label / location 'min' needs to be seen <== by the linker - min: <===== a 'label' -- left justified identifier, followed by a colon +min: <===== a 'label' -- left justified identifier, followed by a colon cmp r14, r15 <== cmp is a 'synthetic' instruction provided <== for your convenince .. actuall sub jl .Lreturn <== 'jump less' . The < relation in concert with @@ -30,10 +30,10 @@ NOTE: Anything after a ; on a line is a comment <== >, < , >= , <= etc are thought of in terms <== of op1 ? op2 mov r14, r15 <== put value in r15 - .Lreturn: <== and go away. Note that 'label' - <== is simply name for place in code - <== and might have nothing on its source - <== code line. +.Lreturn: <== and go away. Note that 'label' + <== is simply name for place in code + <== and might have nothing on its source + <== code line. ret <== go back to them that called us You are to write and push a Single File whose name is MyMult.S which can be called from a C main. Be sure to test with your own main, but DO NOT send me a) your tester.c b) your .elf or other debris from your program development. diff --git a/main.c b/main.c index 307db17a887da91eb5459b9d5b0f6665fe669d53..890086a1259ebd8164223dfab5c507908200fa84 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ #include <libemb/serial/serial.h> #include <libemb/conio/conio.h> -int min(int, int); +int MyMult(int, int); int main(void) { @@ -12,11 +12,11 @@ int main(void) serial_init(9600); - cio_printf("min(9, 2): %i\n\r", min(9, 2)); - cio_printf("min(1, 2): %i\n\r", min(1, 2)); - cio_printf("min(4, 4): %i\n\r", min(4, 4)); - cio_printf("min(-1, -2): %i\n\r", min(-1, -2)); - cio_printf("min(-1, 2): %i\n\r", min(-1, 2)); + cio_printf("min(9, 2): %i\n\r", MyMult(9, 2)); + cio_printf("min(1, 2): %i\n\r", MyMult(1, 2)); + cio_printf("min(4, 4): %i\n\r", MyMult(4, 4)); + cio_printf("min(-1, -2): %i\n\r", MyMult(-1, -2)); + cio_printf("min(-1, 2): %i\n\r", MyMult(-1, 2)); for(;;);