-
-
Save petabyt/6acb95ce6b29f9cd46d78377d68b5d6e to your computer and use it in GitHub Desktop.
arm32 assemble b branch instruction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void assemble_b(uintptr_t *from, uintptr_t *to, uint8_t buf[4]) { | |
uint32_t temp = (uintptr_t)to; | |
// Assemble instruction based on location | |
// of new addr relative to old address | |
if (from < to) { | |
temp = (temp - 8) / 4; | |
memcpy(buf, &temp, 4); | |
} else { | |
temp = 0xffffff - ((from - to + 4) / 4); | |
memcpy(buf, &temp, 4); | |
} | |
// arm32 branch "b" | |
buf[3] = 0xea; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment