summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-09-30 16:31:06 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-09-30 16:31:06 -0700
commit2d5baaa69aada159a474413339cca891838debea (patch)
tree175bad60607029edcce9aeb80003b4b8a584606c
parentdc0bf47feb96884d658d0eceba8ce669c81cf591 (diff)
downloadnasm-2d5baaa69aada159a474413339cca891838debea.tar.gz
assemble.c: cleanups
Formatting and some other minor cleanups. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--assemble.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/assemble.c b/assemble.c
index 9d23240b..91a45d54 100644
--- a/assemble.c
+++ b/assemble.c
@@ -241,30 +241,25 @@ static void out(int64_t offset, int32_t segto, const void *data,
outfmt->output(segto, data, type, size, segment, wrt);
}
-static int jmp_match(int32_t segment, int64_t offset, int bits,
+static bool jmp_match(int32_t segment, int64_t offset, int bits,
insn * ins, const uint8_t *code)
{
int64_t isize;
uint8_t c = code[0];
if ((c != 0370 && c != 0371) || (ins->oprs[0].type & STRICT))
- return 0;
- if (optimizing == 0)
- {
- return 0;
- }
- if (optimizing < 0 && c == 0371 )
- {
- return 0;
- }
+ return false;
+ if (!optimizing)
+ return false;
+ if (optimizing < 0 && c == 0371)
+ return false;
+
isize = calcsize(segment, offset, bits, ins, code);
if (ins->oprs[0].segment != segment)
- return 0;
- isize = ins->oprs[0].offset - offset - isize; /* isize is now the delta */
- if (isize >= -128L && isize <= 127L)
- return 1; /* it is byte size */
+ return false;
- return 0;
+ isize = ins->oprs[0].offset - offset - isize; /* isize is delta */
+ return (isize >= -128 && isize <= 127); /* is it byte size? */
}
int64_t assemble(int32_t segment, int64_t offset, int bits, uint32_t cp,
@@ -449,11 +444,10 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, uint32_t cp,
for (temp = nasm_instructions[instruction->opcode]; temp->opcode != -1; temp++){
int m = matches(temp, instruction, bits);
-
- if (m == 99)
- m += jmp_match(segment, offset, bits, instruction, temp->code);
-
- if (m == 100) { /* matches! */
+ if (m == 100 ||
+ (m == 99 && jmp_match(segment, offset, bits,
+ instruction, temp->code))) {
+ /* Matches! */
const uint8_t *codes = temp->code;
int64_t insn_size = calcsize(segment, offset, bits,
instruction, codes);
@@ -582,7 +576,6 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, uint32_t cp,
} else if (m > 0 && m > size_prob) {
size_prob = m;
}
-// temp++;
}
if (temp->opcode == -1) { /* didn't match any instruction */
@@ -703,10 +696,9 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp,
for (temp = nasm_instructions[instruction->opcode]; temp->opcode != -1; temp++) {
int m = matches(temp, instruction, bits);
- if (m == 99)
- m += jmp_match(segment, offset, bits, instruction, temp->code);
-
- if (m == 100) {
+ if (m == 100 ||
+ (m == 99 && jmp_match(segment, offset, bits,
+ instruction, temp->code))) {
/* we've matched an instruction. */
int64_t isize;
const uint8_t *codes = temp->code;