Author Topic: Asm question(s)  (Read 6068 times)

0 Members and 1 Guest are viewing this topic.

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Asm question(s)
« on: February 17, 2017, 09:14:01 pm »
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) between

mov R8, R6
mov @R8,R6

these?
« Last Edit: February 17, 2017, 09:31:10 pm by Karamel »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #1 on: February 17, 2017, 09:29:12 pm »
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) between

mov R8, R6
Load R6 with the contents of R8
Quote
mov @R8,R6
Load R6 with the contents of memory pointed to by R8

Table 5.2 here:
https://www.ti.com/sc/docs/products/micro/msp430/userguid/as_5.pdf
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #2 on: February 17, 2017, 09:32:18 pm »

Load R6 with the contents of memory pointed to by R8

Table 5.2 here:
https://www.ti.com/sc/docs/products/micro/msp430/userguid/as_5.pdf


Can you give me more details with examples please?

 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #3 on: February 17, 2017, 09:34:23 pm »
Second question:

What is-are the difference(s) between

mov R8, R6
mov @R8+,R6

these?

Let's say: R8 = 0x0001 and R6 = 0x0002

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #4 on: February 18, 2017, 01:17:18 am »
Second question:

What is-are the difference(s) between

mov R8, R6
mov @R8+,R6

these?

Let's say: R8 = 0x0001 and R6 = 0x0002


The first one puts the contents of R8 into R6 so R6 becomes 0x0001
The second one puts the contents of memory at address 0x0001 (memory pointed to by R8) into R6 and increments R8

If 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.
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #5 on: February 18, 2017, 11:29:57 am »
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.
« Last Edit: February 18, 2017, 01:02:31 pm by Karamel »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #6 on: February 18, 2017, 05:26:01 pm »
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
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #7 on: February 24, 2017, 03:11:35 pm »
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 that R8 = R6[3];) but what is that -> Mov.w R6,3(R8)
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #8 on: February 24, 2017, 04:43:15 pm »
Mov.w R6,3(R8) is an indexed store.  The contents of R6 are stored in memory at the contents of R8 + 3.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Asm question(s)
« Reply #9 on: February 24, 2017, 06:41:26 pm »
Second question:

What is-are the difference(s) between

mov R8, R6
mov @R8+,R6

these?

Let's say: R8 = 0x0001 and R6 = 0x0002


Well, if you already know C:

R6 = R8;
R6 = *R8++;

As for Mov.w 3(R6),R8 and Mov.w R6,3(R8) ... R8 = 3[R6]; 3[R8] = R6;

Do you know that in C, 3[R6] and R6[3] 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.
 
The following users thanked this post: rsjsouza

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #10 on: March 03, 2017, 04:31:03 pm »
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?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #11 on: March 03, 2017, 05:06:18 pm »
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.

 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Asm question(s)
« Reply #12 on: March 03, 2017, 06:33:19 pm »
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 :-)
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #13 on: March 12, 2017, 12:32:27 pm »
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?

 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Asm question(s)
« Reply #14 on: March 12, 2017, 04:09:37 pm »
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?

As 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.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #15 on: March 12, 2017, 04:15:12 pm »
BIS ORs the bits of SRC with whatever is in DST and leaves the results in DST.  It does not affect the flags

BIC 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.pdf

N is negative flag,
Z is zero flag
C is non-zero flag

I think the linked document will answer all of your questions re: the instruction set.  It's pretty complete.
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #16 on: March 12, 2017, 08:28:55 pm »
BIS ORs the bits of SRC with whatever is in DST and leaves the results in DST.  It does not affect the flags

BIC 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.pdf

N is negative flag,
Z is zero flag
C is non-zero flag

I think the linked document will answer all of your questions re: the instruction set.  It's pretty complete.

Woooow! 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  ^-^
 

Offline KaramelTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: tr
Re: Asm question(s)
« Reply #17 on: March 12, 2017, 08:32:00 pm »
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?
 

Offline timb

  • Super Contributor
  • ***
  • Posts: 2536
  • Country: us
  • Pretentiously Posting Polysyllabic Prose
    • timb.us
Re: Asm question(s)
« Reply #18 on: March 12, 2017, 09:38:52 pm »
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?

Personally, 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.)
Any sufficiently advanced technology is indistinguishable from magic; e.g., Cheez Whiz, Hot Dogs and RF.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #19 on: March 12, 2017, 10:35:25 pm »
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...

 

Offline timb

  • Super Contributor
  • ***
  • Posts: 2536
  • Country: us
  • Pretentiously Posting Polysyllabic Prose
    • timb.us
Re: Asm question(s)
« Reply #20 on: March 13, 2017, 05:56:07 am »
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...


GCC, 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.)
Any sufficiently advanced technology is indistinguishable from magic; e.g., Cheez Whiz, Hot Dogs and RF.
 
The following users thanked this post: rstofer

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Asm question(s)
« Reply #21 on: March 13, 2017, 12:47:10 pm »
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?

I'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.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Asm question(s)
« Reply #22 on: March 13, 2017, 03:05:02 pm »

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.

Exactly!  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.
 

Offline timb

  • Super Contributor
  • ***
  • Posts: 2536
  • Country: us
  • Pretentiously Posting Polysyllabic Prose
    • timb.us
Re: Asm question(s)
« Reply #23 on: March 13, 2017, 10:57:01 pm »
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...

Whoops, 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, do
ARM JTAG programming, act as a glitch tester, etc.)
Any sufficiently advanced technology is indistinguishable from magic; e.g., Cheez Whiz, Hot Dogs and RF.
 
The following users thanked this post: rstofer

Offline djnz

  • Regular Contributor
  • *
  • Posts: 179
  • Country: 00
Re: Asm question(s)
« Reply #24 on: March 14, 2017, 03:29:21 am »
Why is the 8051 obscene? What's bad about its architecture and how is it remedied in better parts?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf