summaryrefslogtreecommitdiff
path: root/assemble.c
diff options
context:
space:
mode:
Diffstat (limited to 'assemble.c')
-rw-r--r--assemble.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/assemble.c b/assemble.c
index b8b377e..49137c3 100644
--- a/assemble.c
+++ b/assemble.c
@@ -194,7 +194,7 @@ uint64_t handle_opcode(token *t, bytecount *bc, uint8_t isasm, uint64_t address,
if (t->next) {
rs = get_rs(t->next, inst, dbg);
t = (rs != 0xFF) ? t->next : t;
- if (t->next && t->next->id == TOK_OF) {
+ if (t->next) {
of = get_of(t->next, dbg);
t = (of != 0xFF) ? t->next : t;
}
@@ -228,6 +228,9 @@ uint64_t handle_opcode(token *t, bytecount *bc, uint8_t isasm, uint64_t address,
}
}
uint64_t saveaddr = address;
+ uint64_t max_val = 0;
+ uint8_t i = 0;
+ uint8_t j = 1;
switch (type) {
case IMPL:
if (prefix) {
@@ -290,23 +293,22 @@ uint64_t handle_opcode(token *t, bytecount *bc, uint8_t isasm, uint64_t address,
break;
default:
if (of != 0xFF) {
- uint64_t shift = 1;
- uint8_t i = 8;
- uint8_t j = 1;
+ i = 8;
for (; i <= 64; i += 8, j++) {
- if ((int64_t)val.u64 >= ~(int64_t)(shift << (i-1)) || (int64_t)val.u64 <= (int64_t)(shift << (i-1))) {
+ max_val |= ((uint64_t)1 << (i-1));
+ if ((int64_t)val.u64 >= ~(int64_t)(max_val) || (int64_t)val.u64 <= (int64_t)(max_val)) {
opsize = j;
break;
}
}
} else {
- opsize = (val.u64 > 0x00000000000000FF) ? 2 : opsize;
- opsize = (val.u64 > 0x000000000000FFFF) ? 3 : opsize;
- opsize = (val.u64 > 0x0000000000FFFFFF) ? 4 : opsize;
- opsize = (val.u64 > 0x00000000FFFFFFFF) ? 5 : opsize;
- opsize = (val.u64 > 0x000000FFFFFFFFFF) ? 6 : opsize;
- opsize = (val.u64 > 0x0000FFFFFFFFFFFF) ? 7 : opsize;
- opsize = (val.u64 > 0x00FFFFFFFFFFFFFF) ? 8 : opsize;
+ for (; i <= 64; i += 8, j++) {
+ max_val |= (0xFF << i);
+ if (val.u64 <= max_val) {
+ opsize = j;
+ break;
+ }
+ }
}
if (type == 0xFF) {
switch (opsize-1) {