260 likes | 447 Views
Disassembling Instructions. 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.
E N D
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. MSP430 Disassembly
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. 0100 0000 0011 0001 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 R0 MSP430 Disassembly
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 0100 0000 0011 0001 0100 0000 0 0 11 0001 0100 0000 0011 0001 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 MSP430 Disassembly
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.) # 0x0400 0100 0000 0 0 11 0001 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 R0 R0 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code 6. If single or double operand instruction, decode and list destination operand. ,r1 0100 0000 0 0 11 0001 # mov .w 0x0400 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, and operand size. .w mov 0100 0000 0011 0001 R0 mov .w # 0x0400 ,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 R0 0100 0000 1011 0010 0100 0000 1 0 11 0010 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve immediate source operand and increment PC by 2. 0x5a80 # 0100 0000 0011 0001 R0 mov .w # 0x0400 ,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 R0 0100 0000 1 0 11 0010 .w mov MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve absolute destination operand and increment PC by 2. 0x120 ,& 0100 0000 0011 0001 R0 mov .w # 0x0400 ,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 R0 0100 0000 1 0 11 0010 .w 0x5a80 # mov MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, and operand size. .b mov 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0 1 11 1111 0100 0010 0111 1111 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Use constant generator R2 for source operand. #8 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0 1 11 1111 mov .b MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Use register mode for destination operand. ,r15 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0 1 11 1111 mov .b #8 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, (but no operand size is used.) .w 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 000100101 0 11 0000 call MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve immediate destination operand from memory and increment PC by 2. # 0xc012 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 000100101 0 11 0000 .w call MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, and list mnemonic. 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 001111 1111111100 0011 1111 1111 1100 jmp MSP430 Disassembly
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. 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 001111 1111111100 0xc00a jmp (-4 2) + 0xc012 = 0xc00a MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, list mnemonic, and operand size. .w sub 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 1000 0011 0 0 01 1111 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Use constant generator R3 for immediate source operand. #1 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 1000 0011 0 0 01 1111 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 .w sub MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Use register mode for destination operand. ,r15 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 1000 0011 0 0 01 1111 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 .w sub #1 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, and list mnemonic. 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 001000 1111111110 0011 1111 1111 1100 jmp 0xc00a jne 1000 0011 0001 1111 .w sub ,r15 #1 0010 0011 1111 1110 MSP430 Disassembly
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. 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 0xc012 1000 0011 0001 1111 .w sub ,r15 #1 (-2 2) + 0xc016 = 0xc012 001000 1111111110 jne MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Retrieve instruction word, increment PC by 2, and list mnemonic. .w mov 0100 0000 0011 0001 R0 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0001 0 0 11 0000 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 .w sub ,r15 #1 0010 0011 1111 1110 jne 0xc012 0100 0001 0011 0000 MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Use indirect register auto-increment mode for source operand. @r1+ 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0001 0 0 11 0000 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 .w sub ,r15 #1 0010 0011 1111 1110 jne 0xc012 0100 0001 0011 0000 .w mov MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Use register mode for destination operand. (Pop the stack into the PC – ret instruction.) ,r0 (ret) 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0001 0 0 11 0000 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 .w sub ,r15 #1 0010 0011 1111 1110 jne 0xc012 0100 0001 0011 0000 .w mov @r1+ MSP430 Disassembly
Instruction Disassembly How to Disassemble MSP430 Code …Continue the disassembly process. 0100 0000 0011 0001 .w # 0x0400 ,r1 mov 0xc000: 4031 0xc002: 0400 0xc004: 40b2 0xc006: 5a80 0xc008: 0120 0xc00a: 427f 0xc00c: 12b0 0xc00e: c012 0xc010: 3ffc 0xc012: 831f 0xc014: 23fe 0xc016: 4130 R0 0100 0000 1011 0010 .w 0x5a80 ,& 0x120 mov # 0100 0010 0111 1111 mov .b #8 ,r15 0001 0010 1011 0000 .w # 0xc012 call 0011 1111 1111 1100 jmp 0xc00a 1000 0011 0001 1111 .w sub ,r15 #1 0010 0011 1111 1110 jne 0xc012 0100 0001 0011 0000 ,r0 (ret) .w mov @r1+ MSP430 Disassembly