@@ -293,27 +293,44 @@ void asm_thumb_mov_reg_i16(asm_thumb_t *as, uint mov_op, uint reg_dest, int i16_
293293
294294#define OP_B_N (byte_offset ) (0xe000 | (((byte_offset) >> 1) & 0x07ff))
295295
296- void asm_thumb_b_n (asm_thumb_t * as , uint label ) {
296+ bool asm_thumb_b_n_label (asm_thumb_t * as , uint label ) {
297297 mp_uint_t dest = get_label_dest (as , label );
298298 mp_int_t rel = dest - as -> code_offset ;
299299 rel -= 4 ; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
300300 if (SIGNED_FIT12 (rel )) {
301301 asm_thumb_op16 (as , OP_B_N (rel ));
302+ return true;
302303 } else {
303- printf ( "asm_thumb_b_n: branch does not fit in 12 bits\n" ) ;
304+ return false ;
304305 }
305306}
306307
307308#define OP_BCC_N (cond , byte_offset ) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff))
308309
309- void asm_thumb_bcc_n (asm_thumb_t * as , int cond , uint label ) {
310+ bool asm_thumb_bcc_n_label (asm_thumb_t * as , int cond , uint label ) {
310311 mp_uint_t dest = get_label_dest (as , label );
311312 mp_int_t rel = dest - as -> code_offset ;
312313 rel -= 4 ; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
313314 if (SIGNED_FIT9 (rel )) {
314315 asm_thumb_op16 (as , OP_BCC_N (cond , rel ));
316+ return true;
315317 } else {
316- printf ("asm_thumb_bcc_n: branch does not fit in 9 bits\n" );
318+ return false;
319+ }
320+ }
321+
322+ #define OP_BL_HI (byte_offset ) (0xf000 | (((byte_offset) >> 12) & 0x07ff))
323+ #define OP_BL_LO (byte_offset ) (0xf800 | (((byte_offset) >> 1) & 0x07ff))
324+
325+ bool asm_thumb_bl_label (asm_thumb_t * as , uint label ) {
326+ mp_uint_t dest = get_label_dest (as , label );
327+ mp_int_t rel = dest - as -> code_offset ;
328+ rel -= 4 ; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
329+ if (SIGNED_FIT23 (rel )) {
330+ asm_thumb_op32 (as , OP_BL_HI (rel ), OP_BL_LO (rel ));
331+ return true;
332+ } else {
333+ return false;
317334 }
318335}
319336
@@ -422,20 +439,6 @@ void asm_thumb_bcc_label(asm_thumb_t *as, int cond, uint label) {
422439 }
423440}
424441
425- #define OP_BL_HI (byte_offset ) (0xf000 | (((byte_offset) >> 12) & 0x07ff))
426- #define OP_BL_LO (byte_offset ) (0xf800 | (((byte_offset) >> 1) & 0x07ff))
427-
428- void asm_thumb_bl (asm_thumb_t * as , uint label ) {
429- mp_uint_t dest = get_label_dest (as , label );
430- mp_int_t rel = dest - as -> code_offset ;
431- rel -= 4 ; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
432- if (SIGNED_FIT23 (rel )) {
433- asm_thumb_op32 (as , OP_BL_HI (rel ), OP_BL_LO (rel ));
434- } else {
435- printf ("asm_thumb_bl: branch does not fit in 23 bits\n" );
436- }
437- }
438-
439442#define OP_BLX (reg ) (0x4780 | ((reg) << 3))
440443#define OP_SVC (arg ) (0xdf00 | (arg))
441444
0 commit comments