Presentation is loading. Please wait.

Presentation is loading. Please wait.

Disassembling Instructions

Similar presentations


Presentation on theme: "Disassembling Instructions"— Presentation transcript:

1 Disassembling Instructions

2 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code Begin with a “PC” pointing to the first word in program memory. Retrieve instruction word and increment PC by 2. Find and list the corresponding instruction mnemonic using the opcode (most significant 4-9 bits). When appropriate, append “.b” or “.w” using the b/w bit (0=word, 1=byte). If double operand instruction (Table 5), decode and list source operand. If single or double operand instruction (Tables 3 and 5), decode and list destination operand. If jump instruction, sign extend the 10-bit PC offset, multiply by 2, and add to the current PC. List that address. BYU CS 124 MSP430 Disassembly

3 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code 1. Begin with a “PC” pointing to the first word in program memory. 2. Retrieve instruction word and increment PC by 2. R0 R0 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 BYU CS 124 MSP430 Disassembly

4 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code 3. List the instruction mnemonic using the opcode (bits 12-15). 4. Append “.b” or “.w” using the b/w bit when appropriate (0=w, 1=b). mov .w R0 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 BYU CS 124 MSP430 Disassembly

5 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code 5. If double operand instruction, decode and list source operand. (If necessary, fetch operand from memory and increment PC by 2.) # R0 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 0x0400 mov .w R0 BYU CS 124 MSP430 Disassembly

6 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code 6. If single or double operand instruction, decode and list destination operand. ,r1 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w # 0x0400 R0 BYU CS 124 MSP430 Disassembly

7 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, and operand size. mov .w 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 0x0400 mov .w # ,r1 R0 R0 BYU CS 124 MSP430 Disassembly

8 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve immediate source operand and increment PC by 2. # 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 0x0400 mov .w # ,r1 0x5a80 mov .w R0 R0 BYU CS 124 MSP430 Disassembly

9 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve absolute destination operand and increment PC by 2. ,& 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 0x0400 mov .w # ,r1 0x120 mov .w # 0x5a80 R0 R0 BYU CS 124 MSP430 Disassembly

10 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, and operand size. 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 R0 R0 mov .b BYU CS 124 MSP430 Disassembly

11 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Use constant generator R2 for source operand. #8 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 R0 mov .b BYU CS 124 MSP430 Disassembly

12 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Use register mode for destination operand. ,r15 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 R0 mov .b #8 BYU CS 124 MSP430 Disassembly

13 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, (but no operand size is used.) 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 mov .b #8 ,r15 R0 R0 call .w BYU CS 124 MSP430 Disassembly

14 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve immediate destination operand from memory and increment PC by 2. # 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 mov .b #8 ,r15 0xc012 call .w R0 R0 BYU CS 124 MSP430 Disassembly

15 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, and list mnemonic. jmp 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w R0 R0 BYU CS 124 MSP430 Disassembly

16 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Calculate destination address by sign extending the least significant 10 bits, multiplying by 2, and adding the current PC. (-4  2) + 0xc012 = 0xc00a 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w R0 jmp 0xc00a BYU CS 124 MSP430 Disassembly

17 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, and operand size. sub .w 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a R0 R0 BYU CS 124 MSP430 Disassembly

18 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Use constant generator R3 for immediate source operand. #1 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a R0 sub .w BYU CS 124 MSP430 Disassembly

19 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Use register mode for destination operand. ,r15 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a R0 sub .w #1 BYU CS 124 MSP430 Disassembly

20 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, and list mnemonic. jne 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a sub .w #1 ,r15 R0 R0 BYU CS 124 MSP430 Disassembly

21 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Calculate destination address by sign extending the least significant 10 bits, multiplying by 2, and adding the current PC. (-2  2) + 0xc016 = 0xc012 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a sub #1 ,r15 .w R0 jne 0xc012 BYU CS 124 MSP430 Disassembly

22 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, and list mnemonic. mov .w 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a sub #1 ,r15 .w jne 0xc012 R0 R0 BYU CS 124 MSP430 Disassembly

23 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Use indirect register auto-increment mode for source operand. @r1+ 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a sub #1 ,r15 .w jne 0xc012 R0 mov .w BYU CS 124 MSP430 Disassembly

24 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Use register mode for destination operand. (Pop the stack into the PC – ret instruction.) ,r0 (ret) 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a sub #1 ,r15 .w jne 0xc012 R0 mov .w @r1+ BYU CS 124 MSP430 Disassembly

25 How to Disassemble MSP430 Code
Instruction Disassembly How to Disassemble MSP430 Code …Continue the disassembly process. 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 mov .w 0x5a80 # ,& 0x120 0x0400 ,r1 call # 0xc012 mov .b #8 ,r15 .w jmp 0xc00a sub #1 ,r15 .w jne 0xc012 R0 mov .w @r1+ ,r0 (ret) BYU CS 124 MSP430 Disassembly


Download ppt "Disassembling Instructions"

Similar presentations


Ads by Google