Sign in

username or email:

password:



Not a member?
Forgot your Password?

Search msp430



Search tips

Subscribe to msp430



Discussion Groups

See Also

DSPFPGA

Discussion Groups | MSP430 | Assembly language - comparing two unknown, signed 16-bit integers

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.


So far in May, you have voted 0 times ou of a total of 20 votes by the community.
Please help us clean the archives from unuseful discussion threads by using the voting system! Details here.


Is this thread worth a thumbs up?

+7

Assembly language - comparing two unknown, signed 16-bit integers - David Feldman - Aug 21 15:27:53 2012


I am translating a few dozen lines of c code to msp430 assembler (so I am doing this manually rather than trying to integrate a small amount of inline C to what is otherwise an assembly language program).

I have several places where two 16-bit signed integers are being compared arithmetically. Either number may be negative, zero or positive, but is not known prior to assembly time (for example, either/both may be positive, zero or negative). I need to make a conditional jump based on < or > (or <= or >=) relationship between the source and destination values (which are both in registers.) I've not been able to work out a consistent way to code this.

I need help working out the conditional branch instruction(s) to use; particularly whether I need to pre-test either source or destination register so that appropriate use of cmp instruction can be made. If it would help to furnish an example, I'd be glad to, but given that the two register values are unknown, I'm not sure how best to express this.

Thanks for any assistance, example, starting point or guidance.





(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Assembly language - comparing two unknown, signed 16-bit integers - "Redd, Emmett R" - Aug 21 16:29:29 2012

Look at the 'jmp' instructions. Some will work with unsigned and others will work with signed.

Emmett Redd, Ph.D., Professor mailto:E...@MissouriState.Edu
Physics, Astronomy, and Materials Science Office: 417-836-5221
Missouri State University Dept: 417-838-5131
901 S NATIONAL AVENUE FAX: 417-836-6226
SPRINGFIELD, MO 65897 USA Lab: 417-836-3770

It is clear that thought is not free if the profession of certain opinions make it impossible to earn a living. -- Bertrand Russell

> -----Original Message-----
> From: m... [mailto:m...] On Behalf
> Of David Feldman
> Sent: Tuesday, August 21, 2012 2:28 PM
> To: m...
> Subject: [msp430] Assembly language - comparing two unknown, signed 16-
> bit integers
> I am translating a few dozen lines of c code to msp430 assembler (so I
> am doing this manually rather than trying to integrate a small amount
> of inline C to what is otherwise an assembly language program).
>
> I have several places where two 16-bit signed integers are being
> compared arithmetically. Either number may be negative, zero or
> positive, but is not known prior to assembly time (for example,
> either/both may be positive, zero or negative). I need to make a
> conditional jump based on < or > (or <= or >=) relationship between the
> source and destination values (which are both in registers.) I've not
> been able to work out a consistent way to code this.
>
> I need help working out the conditional branch instruction(s) to use;
> particularly whether I need to pre-test either source or destination
> register so that appropriate use of cmp instruction can be made. If it
> would help to furnish an example, I'd be glad to, but given that the
> two register values are unknown, I'm not sure how best to express this.
>
> Thanks for any assistance, example, starting point or guidance.
>
>



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Assembly language - comparing two unknown, signed 16-bit integers - Jon Kirwan - Aug 21 16:35:20 2012

On Tue, 21 Aug 2012 12:27:47 -0700 (PDT), you wrote:

> I am translating a few dozen lines of c code to msp430
> assembler (so I am doing this manually rather than trying to
> integrate a small amount of inline C to what is otherwise an
> assembly language program).
>
> I have several places where two 16-bit signed integers are
> being compared arithmetically. Either number may be
> negative, zero or positive, but is not known prior to
> assembly time (for example, either/both may be positive,
> zero or negative). I need to make a conditional jump based
> on < or > (or <= or >=) relationship between the source and
> destination values (which are both in registers.) I've not
> been able to work out a consistent way to code this.
>
> I need help working out the conditional branch
> instruction(s) to use; particularly whether I need to
> pre-test either source or destination register so that
> appropriate use of cmp instruction can be made. If it would
> help to furnish an example, I'd be glad to, but given that
> the two register values are unknown, I'm not sure how best
> to express this.
>
> Thanks for any assistance, example, starting point or guidance.

Um, is there a problem with JLT and JGE? You need to
understand how the overflow bit works, I suppose. The AV bit
is usually the XOR of the carry outputs of the two most
significant adder stages.

Jon




(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Assembly language - comparing two unknown, signed 16-bit integers - Jon Kirwan - Aug 21 16:37:30 2012

On Tue, 21 Aug 2012 13:35:08 -0700, I wrote:

>The AV bit
>is usually the XOR of the carry outputs of the two most
>significant adder stages.

Sorry, meant V bit. AV is what it is called in the ADSP-21xx
series.

Jon




(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Assembly language - comparing two unknown, signed 16-bit integers - Onestone - Aug 21 21:41:50 2012

i HAVE A RATHER LONG WINDED EXPLANATION OF THIS in a chapter of a book
i started to write a few years ago. If you want a copy of that let me
know. I have also posted it to the group files site.

Al

On 22/08/2012 4:57 AM, David Feldman wrote:
> I am translating a few dozen lines of c code to msp430 assembler (so I am doing this manually rather than trying to integrate a small amount of inline C to what is otherwise an assembly language program).
>
> I have several places where two 16-bit signed integers are being compared arithmetically. Either number may be negative, zero or positive, but is not known prior to assembly time (for example, either/both may be positive, zero or negative). I need to make a conditional jump based on < or > (or <= or >=) relationship between the source and destination values (which are both in registers.) I've not been able to work out a consistent way to code this.
>
> I need help working out the conditional branch instruction(s) to use; particularly whether I need to pre-test either source or destination register so that appropriate use of cmp instruction can be made. If it would help to furnish an example, I'd be glad to, but given that the two register values are unknown, I'm not sure how best to express this.
>
> Thanks for any assistance, example, starting point or guidance.
>
>



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Assembly language - comparing two unknown, signed 16-bit integers - old_cow_yellow - Aug 23 0:49:54 2012

When comparing signed arguments: CMP , you can use:

(a) JL to jump to a if is Less then
(b) JGE to jump to a if is Greater or Equal to

(c) JEQ to jump to a if is Equal to
(d) JNE to jump to a if is Not Equal to

JC, JNC, and JN are more or less useless in this situation.
--- In m..., David Feldman wrote:
> I am translating a few dozen lines of c code to msp430 assembler (so I
am doing this manually rather than trying to integrate a small amount of
inline C to what is otherwise an assembly language program).
>
> I have several places where two 16-bit signed integers are being
compared arithmetically. Either number may be negative, zero or
positive, but is not known prior to assembly time (for example,
either/both may be positive, zero or negative). I need to make a
conditional jump based on < or > (or <= or >=) relationship between the
source and destination values (which are both in registers.) I've not
been able to work out a consistent way to code this.
>
> I need help working out the conditional branch instruction(s) to use;
particularly whether I need to pre-test either source or destination
register so that appropriate use of cmp instruction can be made. If it
would help to furnish an example, I'd be glad to, but given that the two
register values are unknown, I'm not sure how best to express this.
>
> Thanks for any assistance, example, starting point or guidance.
>







(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )