greeeg 460 Posted November 13, 2011 Share Posted November 13, 2011 So I've been working on my own version of a printf Written entirely in ASM it currently supports: - Fixed lengh: %03u = "010" - Zero or space filled: %3X = " A" - Hex - Integer (0 - 65535) - Strings (Due to the memory structure of MSP strings can be in flash or RAM) - Characters - Binary - Octal With all options on size is just over 200 bytes. No support for long ints (32 bits wide)...Yet. No support for signed integers, but I am trying to work that one out. (Any help on implementing these would be great. ) This code isn't exactly fully completed yet but still very functional. run: "make prog" to program to msp430g2231 for a serial demo. Demo code requires mspgcc to build. (I used the uniarc version) xprint.zip PentiumPC, bluehash, gordon and 2 others 5 Quote Link to post Share on other sites
bluehash 1,581 Posted November 13, 2011 Share Posted November 13, 2011 Sweet.. another one. Let me know once you have a little more functionality in place. People like small printfs. Quote Link to post Share on other sites
greeeg 460 Posted November 14, 2011 Author Share Posted November 14, 2011 Update, I have added signed support. After some digging around with mspdebug. Added a feature level define to save code space by disabling certain features. This makes it easy to remove features that are not needed in particular projects. #define X_SUPPORT 0 // Level Features: ~code size of xprint (bytes): // 0 c,s,u,X,d,o,b 254 // 1 c,s,u,X,d 238 // 2 c,s,u,X 200 // 3 c,s,u 190 // 4 u 156 Running xprint(); destroys the values in r15 - r6. This could easily be fixed by adding some push and pops but would increase the code size. If any problems arise I can add them in. xprint-v0.2.zip Quote Link to post Share on other sites
greeeg 460 Posted November 15, 2011 Author Share Posted November 15, 2011 ok. All the features of a good printf function have been added. NEW!! Editable output function. This adds 2 bytes to BSS but no affect on function size. (This should allow a function like sprintf(); to be created very easily.) Define your function before any calls to xprint(); like so: out_dev(&xputc); Format strings parsed to xprint follow these rules %[Zero filled?][Min. Width][Long?][Type] Zero Filled: either '0' or nothing. Min. Width: 1-9 or nothing. Long: 'l' or nothing. Types: [*:2vft2qoj] u - Unsigned[*:2vft2qoj] d - Signed integer[*:2vft2qoj] s - String [ram & flash][*:2vft2qoj] c - Character[*:2vft2qoj] X - Hexadecimal[*:2vft2qoj] b - Binary[*:2vft2qoj] o - Octal (Not sure how useful this really is. Removing saves 8 bytes ) Some examples: xprint("%05u",1234); \\produces "01234" *Zero filled, Width:5, Unsigned xprint("%X",0x2F); \\produces "2F" *Hexadecimal xprint("%9ld",-1234567); \\produces " -1234567" *Width:9, Long, Signed All this with a total footprint of 278 bytes of flash and 2 bytes of static ram. with all functions enabled ASM xprint.s > xprint.o text data bss dec hex filename 278 0 2 280 118 build/xprint.o Still only designed for mspgcc. Support for CCS and IAR should be easy if all compilers use the stack to transfer variable parameters. Will continue to optimize the code. xprint-v0.3.zip Rickta59 and bluehash 2 Quote Link to post Share on other sites
bluehash 1,581 Posted November 15, 2011 Share Posted November 15, 2011 How many bytes does this code take? Quote Link to post Share on other sites
greeeg 460 Posted November 15, 2011 Author Share Posted November 15, 2011 How many bytes does this code take? All this with a total footprint of 278 bytes of flash and 2 bytes of static ram. with all functions enabled bluehash and PentiumPC 2 Quote Link to post Share on other sites
tom12sg 0 Posted May 14, 2013 Share Posted May 14, 2013 Hi, I tried the latest v0.3 program in the post but not able to make it work on my enviroment. I am using a mspgcc-20120406 with chip msp430f2619. I tested my basic putc function using the hardware UART and is able to transmit each char successfully. After which, i add the xprint.s file and changed xputc to use the code in my putc. It is able to compile and assemble successfully but upon run i got "rubblish" keep showing on my PC console. Any advice, please.. Thanks, Tom Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.