1 / 6

Algorithms to Assembly

Algorithms to Assembly. How to translate pseudo code to assembly language programs. MSP430 Program Flow Instructions. Case Unsigned Signed. A eq B jeq jeq A neq B jne jne A >= B jhs jge A < B jlo jl.

Download Presentation

Algorithms to Assembly

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithms to Assembly How to translate pseudo code to assembly language programs

  2. MSP430 Program Flow Instructions Case Unsigned Signed A eq B jeqjeq A neq B jnejne A >= B jhsjge A < B jlojl Note there are no “jls” or “jle” instructions, so must use a compound Statement such as “jle” => jl OR jeq

  3. Conditinal Jump and Control Structures Start with an algorithm in pseudocode/Java/C: unsigned integer If ( a >= b ) { a = a + b } else { a = a -b } 1. Resource allocation Assign variables to registers 2. Convert to Register Transfer Notation Swap out variables with registers Change “=“ to “<-” a => r5 b => r6 if( r5 >= r6 ){ r5 <- r5 + r6 } else { r5 <- r5 – r6 } 3. RTN to Assembly Match forms of Algothm->Assembly Insert Opcodes. cmp r5,r6 jhsNotLessThan sub r5,r6 jmp End NotLessThan: add r5,r6 End:

  4. Conditinal Jump and Control Structures Usually an “if” statement implies a “cmp” RTN to Assembly: The If/Then Statement cmp r5,r6 jhsNotLessThan NotLessThan: add r5,r6 if ( r5 >= r6 ) { r5 <- r5 + r6 } else { r5 <- r5 –r6 } sub r5,r6 jmp End End: The “else” part does not require a separate jump. If/then statements cause jmpsforward

  5. Conditinal Jump and Control Structures Usually a “while” statement implies a “cmp” RTN to Assembly: The While Statement Part 1 “while” loops cause jmp backwards while ( n > 0 ) { s1… } Loop: s1… dec r6 cmp #0,r6 jnz Loop End: Until condiion is met, then Jmp forward.

  6. RTN to Assembly: The While Statement Part 2 Usually a “while” statement implies a “cmp” “while” loops cause jmp backwards while ( n > 0 ) { s1… } Loop: cmp #0,r6 dec r6 jz End s1… jmp Loop End: Until condiion is met, then Jmp forward.

More Related