Warm tip: This article is reproduced from stackoverflow.com, please click
assembly nasm x86 as86

AS86 Set Origin Address (x86 assembly)

发布于 2020-04-10 16:11:36

Does anyone know how to set an origin address using AS86 syntax?

With NASM, you would put, for example (in a BIOS bootloader): ORG 0x7c00.

Does anyone know what the AS86 equivalent is? Or what the functional equivalent would be?

I'm using AS86 because I'm compiling programs with the 16-bit assembly output from BCC (Bruce's C Compiler). If anyone knows of a true 16-bit C compiler that will produce NASM-compatible assembly, that would also essentially solve my problem (since, unlike with AS86, I have had no issue with getting NASM's raw binaries to work using particular memory address offsets).

2/1 Edit with example AS86 code:

ORG 0x7c00

USE16

mov ah, 0x0e
mov al, 0x61
xor bx, bx
int 0x10

ORG 0x7DFE
.word 0xAA55

Generated symbol file (seems correct):

+ 00007C00 ----- $start
+ 00007E00 ----- $end

And the generated binary is 512 bytes, meaning (I think) that the ORG directive at the end is padding out the rest of the file in the same way as would happen with NASM using the "times" directive.

Thanks!

Final edit: So this was solved. From the help I received, the solution to the origin address issue was to put the origin address at the beginning using the ORG directive and then to also use the ORG directive at the end to specify the memory address at which the program should be located at that particular point in the file. Then, the assembly language file has to be compiled in as86 using the -s option to generate a symbol file.

Then, the reason this code wasn't working even though the memory address issue was solved was because I hadn't read the man pages very carefully and was effectively loading (into the registers) the contents of the memory locations specified in the operands I was using, rather than their immediate values.

So, after fixing that issue as well, the test code runs on boot and prints the 'a' character as expected.

Thanks again to everyone.

Questioner
Learning
Viewed
63
Nate Eldredge 2020-02-02 03:31

The first issue was needing to use -s, as pointed out by Jester's comment.

As you noted, the code then seemed to be laid out correctly but still didn't work. So I assembled your code and disassembled the output, and the issue became clear.

as86 uses different syntax than nasm and other traditional Intel-style assemblers. In particular, an instruction like mov ah, 0x0e is parsed as what you might understand as mov ah, [0x0e]; it's a move of one byte from memory address 0x0e. Obviously, you meant to load the immediate value 0x0e so you have to write mov ah, #0x0e.

It seems like it would be a good idea to read carefully through the as86 man page before proceeding any further.