0

As an assignment for my class i have to implement a code in assembler allowing to jump a specific distance for our arm7 processor we are simulating. My question is, how do we specify the distance we want to jump in code?

I currently have this code :

main : 

mov r1, #5

add r0, r2, r3

b test

mov r1, #5



test :

add r0, r2, r3

mov r1, #5

My aim is to be able to jump a few bits to see if my simulations sees that there is a jump and that she calculates correctly the jumping distance

Thank you in advance for any help

DavidGL
  • 13
  • 3
  • 3
    `b test` is already a jump with a specific distance. Isn't that good enough? Anyway, depending on your assembler, instead of using a label you could use an offset from the current location, usually something like `$+4` or `.+4` – Jester Feb 27 '20 at 18:46
  • Does Thumb mode allow you to `add pc, #16` or something? I think you can do that in ARM mode. Unlike most ISAs, the program counter is one of the general-purpose registers in ARM, and you can read and/or write it with most instructions. (Although there are special restrictions about not using PC for some). `pc` reads as 2 instructions after the current one. – Peter Cordes Feb 27 '20 at 19:07
  • assembly language is specific to the assembler, what assembler are you using (kiel, gnu as, etc)? – old_timer Feb 27 '20 at 19:58
  • 1
    I dont think gnu assembler for thumb lets you directly set the offset, it either wants a label or the specific destination address. you can of course do it mathmatically, move pc into a lower register add/subtract the offset, orr with 1 if needed, bx. – old_timer Feb 27 '20 at 20:05
  • @old_timer: In GAS, `.` is the start of the current instruction. So Jester's `b .+4` suggestion gets the assembler to calculate the right encoding to reach that target. (And yes, it's not going to be just `+4`, so you're right you can't specify the branch *offset* directly.) – Peter Cordes Feb 28 '20 at 01:46
  • I didnt see that Jester had already said that I tried 8 and +8 not .+8, sorry. – old_timer Feb 28 '20 at 16:25

0 Answers0