assembly - How to generate binary from MSP430 assembler with correct jumps? -
i'm programming msp430 in c language simulation of real microcontroller (or emulator if want). when prepare test.s file msp430:
.text .global main .type main, @function main: mov #8,r4; add r5,r5; // r5 = 0 jz l1; add r6,r6; // r6 = 0 jz l2; push r6; // break purpose l1: mov #0x1234,r8; push r10; l2: mov #0x5678,r9; push r11;
i got such verification (by msp430) file test.lst:
test.elf: file format elf32-msp430 disassembly of section .text: 00000000 <main>: 0: 34 42 mov #8, r4 ;r2 as==11 2: 05 55 rla r5 ; 4: 00 24 jz $+2 ;abs 0x6 6: 06 56 rla r6 ; 8: 00 24 jz $+2 ;abs 0xa a: 06 12 push r6 ; 0000000c <l1>: c: 38 40 34 12 mov #4660, r8 ;#0x1234 10: 0a 12 push r10 ; 00000012 <l2>: 12: 39 40 78 56 mov #22136, r9 ;#0x5678 16: 0b 12 push r11 ;
the problem jumps (i.e. jz) never going happen. whatever z flag set before jz, code moving through jz. emulation of jz is:
- read code (16 bits) , offset (10 bits lsb)
- check z flag (0 or 1)
- if z = 0, move next section of code (pc++)
- else, set pc = pc + 2*offset
in binary file, generated msp430, offset value 0 (should more 0 move pc code section).
how make jumps work correctly? or maybe generation of binary file broken?
your test.elf
file object file, still contains unresolved relocations.
after assembling , linking file (with c compiler, c startup code calls main
), jumps correct:
$ msp430-gcc -mmcu=msp430f5529 -minrt -o test.elf test.s $ msp430-objdump -d test.elf ... 0000454e <main>: 454e: 34 42 mov #8, r4 ;r2 as==11 4550: 05 55 rla r5 ; 4552: 03 24 jz $+8 ;abs 0x455a 4554: 06 56 rla r6 ; 4556: 04 24 jz $+10 ;abs 0x4560 4558: 06 12 push r6 ; 0000455a <l1>: 455a: 38 40 34 12 mov #4660, r8 ;#0x1234 455e: 0a 12 push r10 ; 00004560 <l2>: 4560: 39 40 78 56 mov #22136, r9 ;#0x5678 4564: 0b 12 push r11 ; ...
it possible generate binary this:
$ msp430-objcopy -o binary test.elf test.bin
however, resulting file not useful because not contain start address. better off creating (and using in simulator) intel hex file:
$ msp430-objcopy -o ihex test.elf test.ihex
Comments
Post a Comment