linux - 在 as86/bin86 中包含二进制文件

标签 linux x86-16 as86

我在 i8086 汇编器中编写了一些代码,应该将 80x25 图像放入 VRAM 中并将其显示在屏幕上。

entry start
start:
    mov di,#0xb800  ; Point ES:DI at VRAM
    mov es,di
    mov di,#0x0000
    mov si,#image   ; And DS:SI at Image

    mov cx,#0x03e8  ; Image is 1000 bytes

    mov bl,#0x20    ; Print spaces

; How BX is used:
; |XXXX XXXX XXXXXXXX|
;            ^^^^^^^^^  BL contains ascii whitespace
;  ^^^^                 BH higher 4 bits contain background color
;       ^^^^            BH lower  4 bits contain unused foreground color

img_loop:
    seg ds          ; Load color 
    mov bh,[si]

    seg es          ; Write a whitespace and color to VRAM
    mov [di],bx

    add di,#2   ; Advance one 'pixel'
    sal bh,#4   ; Shift the unused lower 4-bits so that they become background color for the 2nd pixel

    seg es
    mov [di],bx

    add di,#2   
    add si,#1

    sub cx,#1   ; Repeat until 1 KiB is read
    jnz img_loop

endless:
    jmp endless

image:
GET splash.bin

问题是我无法让 as86 汇编器包含图像文件中的二进制数据。我看过the man page但我找不到任何有效的东西。

如果我尝试构建上面的代码,它不会给我任何错误,但链接器生成的输出文件大小只有 44 字节,所以显然它没有费心放入 1000 字节图像。

有人可以帮我吗?我做错了什么?

最佳答案

我不确定这是否会对您有帮助,因为我从未尝试过 8086 代码。但你也许能够让它发挥作用。

objcopy程序可以将二进制对象转换为各种不同的格式。就像 man objcopy 中的这个例子一样页面:

objcopy -I binary -O <output_format> -B <architecture> \
  --rename-section .data=.rodata,alloc,load,readonly,data,contents \
  <input_binary_file> <output_object_file>

因此,您将拥有一个带有 <input_binary_file> 的目标文件在名为 .rodata 的部分中。但你可以随意命名它。然后使用链接器将机器代码链接到图像数据。

符号名称也是为您创建的。同样来自手册页:

-B
--binary-architecture=bfdarch
Useful when transforming a architecture-less input file into an object file. In this case the output architecture can be set to bfdarch. This option will be ignored if the input file has a known bfdarch. You can access this binary data inside a program by referencing the special symbols that are created by the conversion process. These symbols are called _binary_objfile_start, _binary_objfile_end and _binary_objfile_size. e.g. you can transform a picture file into an object file and then access it in your code using these symbols.

关于linux - 在 as86/bin86 中包含二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29037797/

相关文章:

php - 通过 Linux 中的 Php 计算共享 Windows 驱动器上的文件

assembly - 使用 ld 链接文件以输出二进制文件会在操作系统开发中出错

debian - 如何在 debian 6.0 中安装 as86?

c - 如何检查输出流的缓冲区类型?

php - 使用 facebook 帐户登录时显示这样的错误,我该怎么办?

linux - 从 bash 脚本作为 cronjob 启动 bash 脚本

linux - DOS 上的 NASM(英特尔 8086): invalid effective address

c - 如何告诉 GCC 为实模式生成 16 位代码

assembly - Linux内核0.01引导加载程序使用rep movw,而不是rep movsw?这实际上是重复普通的 MOV 吗?