Asm question(s) - Page 1
Forum section: electronics / beginners

author: Karamel
author_rank: Regular Contributor
timestamp: February 17, 2017, 09:14:01 pm
content: Hi,I am learning asm programming for MSP430. (after I will program it with c but, now, I must learn asm codes in order to distinguish microcontroller architecture)The first question:What is-are the difference(s) betweenmov R8, R6mov @R8,R6these?

author: rstofer
author_rank: Super Contributor
timestamp: February 17, 2017, 09:29:12 pm
content: Quote from: Karamel on February 17, 2017, 09:14:01 pmLoad R6 with the contents of R8QuoteLoad R6 with the contents of memory pointed to by R8Table 5.2 here:https://www.ti.com/sc/docs/products/micro/msp430/userguid/as_5.pdf

author: Karamel
author_rank: Regular Contributor
timestamp: February 17, 2017, 09:32:18 pm
content: Quote from: rstofer on February 17, 2017, 09:29:12 pmCan you give me more details with examples please?

author: Karamel
author_rank: Regular Contributor
timestamp: February 17, 2017, 09:34:23 pm
content: Second question:What is-are the difference(s) betweenmov R8, R6mov @R8+,R6these?Let's say: R8 = 0x0001 and R6 = 0x0002

author: rstofer
author_rank: Super Contributor
timestamp: February 18, 2017, 01:17:18 am
content: Quote from: Karamel on February 17, 2017, 09:34:23 pmThe first one puts the contents of R8 into R6 so R6 becomes 0x0001The second one puts the contents of memory at address 0x0001 (memory pointed to by R8) into R6 and increments R8If you read page 5-7, you will see that the format of the MOV instruction is MOV src,dst. The source of data for the move is specified by the first field and the destination is specified by the second field.

author: Karamel
author_rank: Regular Contributor
timestamp: February 18, 2017, 11:29:57 am
content: Thank you so much for replying.I am freshman at asm programming. I dont want to misunderstand anyting and don't wanna build a information tower on mistakes. My questions may sometimes be easy, I don't know maybe sometimes hard or meanless but, I believe that the best learning method it question and answer method.

author: rstofer
author_rank: Super Contributor
timestamp: February 18, 2017, 05:26:01 pm
content: Here is a tutorial on MSP430 assembly language programming. Google has a lot of references...http://www.ece.utep.edu/courses/web3376/Notes_files/ee3376-assembly.pdf

author: Karamel
author_rank: Regular Contributor
timestamp: February 24, 2017, 03:11:35 pm
content: Thank you so much for link.I have a confused situation here.I know that.Mov.w 3(R6),R8(It's meaning in c is thatR8 = R6;) but what is that ->Mov.w R6,3(R8)

author: rstofer
author_rank: Super Contributor
timestamp: February 24, 2017, 04:43:15 pm
content: Mov.w R6,3(R8) is an indexed store. The contents of R6 are stored in memory at the contents of R8 + 3.

author: brucehoult
author_rank: Super Contributor
timestamp: February 24, 2017, 06:41:26 pm
content: Quote from: Karamel on February 17, 2017, 09:34:23 pmWell, if you already know C:R6 = R8;R6 = *R8++;As for Mov.w 3(R6),R8 and Mov.w R6,3(R8) ... R8 = 3; 3 = R6;Do you know that in C, 3 and R6 mean the same thing? And both mean *(R6+3) or *(3+R6)Crazy language. I liked it better when it was spelled R6!3 or 3!R6 or !(R6+3) in C's predecessor.

author: Karamel
author_rank: Regular Contributor
timestamp: March 03, 2017, 04:31:03 pm
content: Thnak you so much for answers.Okay, I have a different type of question here. I didnt want to open a new topic for it.I got what stack pointer is, but I did not imagine it. How does it works? How can I imagine its working?

author: rstofer
author_rank: Super Contributor
timestamp: March 03, 2017, 05:06:18 pm
content: A stack is a Last In - First Out data structure. Just like a stack of plates in a cabinet. It is easiest to take the top plate.In the normal Call-Return arrangement for subroutines, the address of the instruction following the Call is placed on the stack at the stack pointer (SP) and the stack pointer is decremented (usually). More often than not, stacks grow downward.When the called function wants to return, it increments the SP, grabs the return address and branches back.There are differences in implementation about where the SP points. Is it pointing at the return address or is it pointing at the memory address below the cell containing the return address. I'm not going to get into this because it's just a detail of where, exactly, the SP is pointing. Read the manual...If the called function requires parameters, the arguments are pushed on the stack before the call. The function knows where, relative to the stack pointer, these parameters are located. So it uses the SP as a base register to find the parameters.

author: brucehoult
author_rank: Super Contributor
timestamp: March 03, 2017, 06:33:19 pm
content: I never came across MSP430 before. Looks like a PDP11 where they said "let's make 16 registers instead of 8, and live with a few less addressing modes"Only Rn and nnnn(Rn) for destination! And two more including autoincrement on src! No auto-decrement.BIC and BIS just like PDP11 and VAX.Looks pleasant enough, but I prefer RISC-V :-)

author: Karamel
author_rank: Regular Contributor
timestamp: March 12, 2017, 12:32:27 pm
content: Hi,Thanks for all answers.I got a new question. I didn't understand what bit.w r6,r7 does.I read its explanation, It changes state flags(carry, zero etc) but when, why, how?

author: brucehoult
author_rank: Super Contributor
timestamp: March 12, 2017, 04:09:37 pm
content: Quote from: Karamel on March 12, 2017, 12:32:27 pmAs with other CPUs with this instruction (6800, 6809, 6502, 8086 (called TEST)) it is exactly the same as the AND instruction except that it doesn't write the result to the "destination" register.The flags are usually set exactly the same as for any other instruction i.e. the Z flag is set if all bits of the result are 0, the N flag is set if the most significant bit of the result is 1. The V flag is set to 0 (no overflow is possible). For some reason on the MSP430, despite no "carry" is possible as such, the AND and BIT instructions set the C flag to the opposite of the Z flag i.e. to 1 if the all result bits are 0, and to 0 otherwise.

author: rstofer
author_rank: Super Contributor
timestamp: March 12, 2017, 04:15:12 pm
content: BIS ORs the bits of SRC with whatever is in DST and leaves the results in DST. It does not affect the flagsBIC ANDs the complement of SRC with whatever is in DST and leaves the results in DST. It does not affect the flags.BIT ANDs the SRC and DST registers and does not save the result. It sets the N, Z and C flags.Page 61 here:http://www.ti.com/lit/ug/slau049f/slau049f.pdfN is negative flag,Z is zero flagC is non-zero flagI think the linked document will answer all of your questions re: the instruction set. It's pretty complete.

author: Karamel
author_rank: Regular Contributor
timestamp: March 12, 2017, 08:28:55 pm
content: Quote from: rstofer on March 12, 2017, 04:15:12 pmWoooow! That's it which I was looking for. This guide explains bit operation very well. I was just seracing my teacher's notes and they was not clear to see what it is...Thank you so much

author: Karamel
author_rank: Regular Contributor
timestamp: March 12, 2017, 08:32:00 pm
content: Can I ask one more question about msp430 series microcontrollers?That productions are good or rubbish? What do people think about and use msp430 around world?For example why msp430 instead of st-arm m series or etc?

author: timb
author_rank: Super Contributor
timestamp: March 12, 2017, 09:38:52 pm
content: Quote from: Karamel on March 12, 2017, 08:32:00 pmPersonally, I like them. They're great little 16-bit MCUs that are very low power (especially the FRAM parts), not super expensive, have nice peripherals, have a very decent set of C libraries (with a HAL that actually works and isn't bloated).They're used in a lot of products across many industries. For example, open a Fluke multimeter and you're likely to find one!There's even an Arduino-like IDE available for them called Enegia. (Which is nice if you want to hit the ground running without dealing with Code Composer Studio or IAR. I use Energia and EmbedXcode, which lets me do the actual C coding using Xcode as my IDE and simply calls GCC from the Energia package; I don't actually use the Arduino APIs.)

author: rstofer
author_rank: Super Contributor
timestamp: March 12, 2017, 10:35:25 pm
content: I have never played with the MPS parts.What toolchain can I use that is both unlimited and free?What do I need, in the general case, for device programming? I assume the Launchpad boards will be programmed with no outside device, right? But what if I embed an MPS430 in my own PCB?I like the idea of a DIP package and the idea of a 16 bit processor. I haven't studied the device at all but, from 10,000 feet up, it seems pretty interesting.I suppose I should ask over in the Microcontrollers Forum but since we're here...

author: timb
author_rank: Super Contributor
timestamp: March 13, 2017, 05:56:07 am
content: Quote from: rstofer on March 12, 2017, 10:35:25 pmGCC, IAR, CrossWorks and TI's own Code Composer Studio all support the MSP430. IAR and CCS are code-limited free and GCC is unlimited free. I believe you also get a full CCS license with a LaunchPad purchase now. CCS uses either TI's own custom compiler *or* GCC, depending on what you select.I use GCC. Because I'm lazy, I use the version that ships with Energia. That way I don't need to compile it or deal with all the platform files. I use Xcode as my IDE. (I don't use any of the Arduino APIs that are part of Energia, I simply use it as a source for GCC and the platform files.)

author: brucehoult
author_rank: Super Contributor
timestamp: March 13, 2017, 12:47:10 pm
content: Quote from: Karamel on March 12, 2017, 08:32:00 pmI've never used one but I can't see any reason that I wouldn't if a 16 bit CPU will do the job. The instruction set is reasonably sane and easy for a C compiler to generate decent code for -- as I said earlier in this thread 'Looks like a PDP11 where they said "let's make 16 registers instead of 8, and live with a few less addressing modes'.The same goes for SuperH.If you write things in C and have a decent compiler for whatever CPU you choose, then it comes down to what parts are available, at what cost, what power consumption, what speed, how much memory, how much I/O etc.MSP430 seems to have some *extremely* low power parts available.8051 and early PIC (not PIC32, which is MIPS) are obscene architectures and I'd do almost anything to stay away from them.But SuperH, MSP430, ARM, RISC-V, 68K/Coldfire, MIPS ... no problem with any of them as far as instruction sets goes.

author: rstofer
author_rank: Super Contributor
timestamp: March 13, 2017, 03:05:02 pm
content: Quote from: brucehoult on March 13, 2017, 12:47:10 pmExactly! I have used the 80251 and a bunch of PIC16F and it's not something I really enjoy. I really like the ARM chips and have used the LPC2106, LPC2148 and the LPC1768 (mbed). These are very nice chips and I really like the mbed concept with the online toolchain.I have mixed feelings about the STM32F. I haven't spent enough time with them to write my own drivers and I don't really care for the HAL and CubeMx. Maybe if I spent more time...OTOH, there is a case to be made for smaller devices in a DIP package with a decent architecture. Something simple with an elegant instruction set.

author: timb
author_rank: Super Contributor
timestamp: March 13, 2017, 10:57:01 pm
content: Quote from: rstofer on March 12, 2017, 10:35:25 pmWhoops, I forgot to answer the rest of your question in my last reply!As for device programming, LaunchPads include onboard emulators for programming and debugging.Some of the newer ones even include EnergyTrace++ functionality, which is really cool. In a nutshell, it lets you monitor energy usage as your program executes on the MCU. It has a very high dynamic range, showing microamps to hundreds of milliamps. Using special breakpoints in the code, it can also directly relate this energy usage to specific sections of code in the IDE. (Note this functionality only works with CCS.)For programming a chip on your own PCB, you can actually use a LaunchPad board for that if you want (there are jumpers to disconnect the programming lines from the emulator and MCU portions of the board). The MSP430 uses a proprietary single wire debug and programming system. So all you need to do is bring out the TEST and RESET pins on your board and you should be set.If for some reason you don't want to use the LaunchPad as a programmer, you can buy dedicated ones (produced by TI and third parties). There is also an Open Source Hardware/Software thing called the GoodFet, which is a small little USB dongle that can act as an MSP430 programmer (plus program TI's wireless parts, doARM JTAG programming, act as a glitch tester, etc.)

author: djnz
author_rank: Regular Contributor
timestamp: March 14, 2017, 03:29:21 am
content: Why is the 8051 obscene? What's bad about its architecture and how is it remedied in better parts?

author: brucehoult
author_rank: Super Contributor
timestamp: March 14, 2017, 08:37:47 am
content: Quote from: djnz on March 14, 2017, 03:29:21 amVery poor support for anything except registers and absolute addressing, not pointers. Stack is only push/pop, can't be referenced with an offset. Most jumps are within a 2KB code page, rather than e.g. much more useful +/- 1KB relative. 64 KB RAM banks, not flat addressing.Sure, it's fine as a direct replacement for random logic, state machines etc, with small amounts of code and small amounts of state written directly in assembler. But it's awful for targeting with portable languages.Considering it was designed years after and is much worse to program than the 8080 you have to ask whyyyyy?Of course the 251 is a big improvement, but that's not the topic.