Advertisement

03.26.2008 at 12:57AM PDT, ID: 23269676 | Points: 500
[x]
Attachment Details
conversion of Assembly into C
Tags: Freescale, DSP56800ERM, assembly language targetting the MC56F83xx microcontroller
Can someone please help me in figuring out what is going on in the snippet?I'm trying to convert an assembly language code into C.So if I could have the C equivalent of this, that would be great.
thank you
1:
2:
3:
4:
5:
6:
7:
8:
tfr A,B                     /* move A to B */
    neg B                       /* B negated, negative result is converted to positive */
    move.w B1,X0                /* move MSB of B to X0 */
    clr B                       /* clear B */
    move.w X0,B0                /* move X0 to LSB of B  */
    dec.w C                     /* decrement C, C contains ProportionalGainScale -> negative value */   
    asrr.l C,B                  /* shift B to the right by the value contained in C, since the
                                   C is negative B is shifted to the left */
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: jurjess
Question Asked On: 03.26.2008
Participating Experts: 2
Points: 500
Views: 0
Translate:
Loading Advertisement...
03.26.2008 at 01:24AM PDT, ID: 21209690

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 02:57AM PDT, ID: 21210030

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 04:39AM PDT, ID: 21210542

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 04:43AM PDT, ID: 21210570

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 06:32AM PDT, ID: 21211359

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 07:03AM PDT, ID: 21211692

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 07:06AM PDT, ID: 21211722

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 07:19AM PDT, ID: 21211852

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 07:49AM PDT, ID: 21212201

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 07:02PM PDT, ID: 21218005

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 05:49AM PDT, ID: 21220696

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.26.2008 at 01:24AM PDT, ID: 21209690

Rank: Guru

it should be something like this:

short int A, B, C, X;  // assumed to be 16 bits

B=A;
B = -B;
X = (X && FF00) | (B >> 8);
B = 0;
B = X & FF;
C--;
B = C>0 ? ( B >> C) : (B << -C);
 
03.26.2008 at 02:57AM PDT, ID: 21210030
I think the snippet is too short to figure out what is trying to do.
It is not easy to make C from it.

A, B and C are 36 bit accumulators (32 bit number, for example A0 [LSP] and A1 [MSP], + 4 bit extension, for example A2), X0 is 16 bit register.

The C code above is not only wrong, but harder to understand than the initial snippet.

Another remark: "dec.w C" is not doing decrement of C, but the decrement of C1, because C is accumulator.
 
03.26.2008 at 04:39AM PDT, ID: 21210542
A,B and C are 32 bit registers (with 4 bits for sign extension). do you have any idea why this computation would be carried out? I'm trying to look at the reason too.
 
03.26.2008 at 04:43AM PDT, ID: 21210570
a structure is passes to the function where R2 is the address of the pointer that points to the structure.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
sub Y1,Y0            		/* Y0 <= Y0 - Y1 */ 
                              	/*  Y0 <= desiredValue - measuredValue */
 
    move.w X:(R2+0x0006),C 		/* C <= ProportionalGainScale */
 
    tst.l   C                   /* test C (ProportionalGainScale) */
    bge     POSITIVE_PROP_SHIFT  /* if C (ProportionalGainScale) is positive, jump to POSITIVE_PROP_SHIFT. 
                                   Positive C means shift to right, overflow cannot occur */
 
 
    move.w X:(R2),A       		/* A <= ProportionalGain */
    mpy Y0,A1,A          		/* A <= Y0*A1 */
    nop							/* A <= ProportionalGain * (desiredValue - measuredValue) */
 
/* arithmetic left or right shift according to ProportionalGainScale
   value, member of the mc_sPIparams1_limitSc structure */
//---------------------------------------------------------------------
    bge POS_PROP                /* if the result in A is positive, jump to POS_PROP otherwise 
                                   is negative and then continue */
    
    tfr A,B                     /* move A to B */
    neg B                       /* B negated, negative result is converted to positive */
    move.w B1,X0                /* move MSB of B to X0 */
    clr B                       /* clear B */
    move.w X0,B0                /* move X0 to LSB of B  */
    dec.w C                     /* decrement C, C contains ProportionalGainScale -> negative value */   
    asrr.l C,B                  /* shift B to the right by the value contained in C, since the
                                   C is negative B is shifted to the left */
    nop
    tst.w B1                    /* test B1 */
    beq STANDARD_PROP_CALC      /* if B1 is zero, jump to STANDARD_PROP_CALC */
    
    move.l  #0x80000000,A       /* otherwise A is saturated to minimal negative value */
    jmp PROP_PART_SAT           /* jump to PROP_PART_SAT */
    
POS_PROP:                       /* jump here in case of positive A */
    clr B                       /* clear B */
    move.w A1,B0                /* move MSB of A to B0 */
    dec.w C                     /* decrement C, C contains ProportionalGainScale -> negative value */
    asrr.l C,B                  /* shift B to the right by the value contained in C, since the
                                   C is negative B is shifted to the left */
    nop
    tst.w B1                    /* test B1 */
    beq STANDARD_PROP_CALC      /* if B1 is zero, jump to STANDARD_PROP_CALC  */ 
    
    move.l  #0x7FFFFFFF,A       /* otherwise A is saturated to maximal positive value */
    jmp PROP_PART_SAT           /* jump to PROP_PART_SAT */
Open in New Window
 
03.26.2008 at 06:32AM PDT, ID: 21211359
Just some remarks:
- BGE after MPY checks if there was overflow in 16bit multiplication (MSP of accumulator was set), not if the result is >= 0.
- ASRR.L C, B does not necessarily shifts to the left (only least 5 bits of MSP of C are used)
- DEC.W C may be done for compensation of 2-complement representation of negative numbers (?)
 
03.26.2008 at 07:03AM PDT, ID: 21211692
ASRR.L shifts to left if the value in register is negative
how do you mean by compensation of negative numers?
also you said the C code representation above by "jaime" was wrong, could you please give me the right version of the C translation to the assembly code I pasted above?
 
03.26.2008 at 07:06AM PDT, ID: 21211722
Yes, you are right about ASSR.L, I was reading wrong documentation.
Also, DEC.W C has nothing to do with negative numbers, as I thought...
 
03.26.2008 at 07:19AM PDT, ID: 21211852
any help with the code translations?
 
03.26.2008 at 07:49AM PDT, ID: 21212201
Here is the C code, however still not "complete" since the EXT is not taken into account.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
  short X0 = 0;
  short *A0, *A1, *B0, *B1, *C0, *C1;
  int   A = 0, B = 0, C = 0;
 
  A0 = (short*) &A; A1 = A0 + 1;
  B0 = (short*) &B; B1 = B0 + 1;
  C0 = (short*) &C; C1 = C0 + 1;
 
  *A1 = -1000;
  *C1 = -7;
 
  B = A;
 
  B = -B;
 
  X0 = *B1;
  B = 0;
  *B0 = X0;
  /* equivalent: B = (B >> 16) & 0x0000FFFF; */
 
  (*C1)--;
 
  B = (*C1 > 0) ? (B >> *C1) : (B << -(*C1));
Open in New Window
 
03.26.2008 at 07:02PM PDT, ID: 21218005
could you also tell me what the snippet below means?As you can see it is to manage the saturation flag. but it also changes the value of the structure passed to the function this snippet's in.The address of the pointer that points to the base of the structure is in R2 so I dont understand why the filling of register R1 with 0 and R1 with 1?
1:
2:
3:
/* to manage saturation flag, R1=0 & R0 =1 */
    moveu.w #0,R1
    moveu.w #1,R0
Open in New Window
 
03.27.2008 at 05:49AM PDT, ID: 21220696
Well, R0 and R1 belong to AGU and can be used for many things, for example:
- Shadowed for use with fast interrupt processing.
- Modulo arithmetics (R0 and/or R1 are used as source registers in the addressing mode or instruction).
More on this, you can find in the documentation (http://www.freescale.com/files/dsp/doc/ref_manual/DSP56800ERM.pdf)
I cannot realize in which case you are here...
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628