在 MASM 8086 程序集中读取多个文件

Reading multiple files in MASM 8086 Assembly

我想在 MASM 中制作动画并且我一直在这样做。我如何使它更有效率?就像把它变成一个字符串数组?以及如何在递增时仅使用一个地址来访问它一次?我真的需要它,因为在主过程中,我的代码因为过于硬编码或彼此相距太远而越界

frame1FileName DB 'frame1.bin', 0
frame2FileName DB 'frame2.bin', 0
frame3FileName DB 'frame3.bin', 0
frame4FileName DB 'frame4.bin', 0
frame5FileName DB 'frame5.bin', 0
frame6FileName DB 'frame6.bin', 0
frame7FileName DB 'frame7.bin', 0
frame8FileName DB 'frame8.bin', 0
frame9FileName DB 'frame9.bin', 0
frame10FileName DB 'frame10.bin', 0
frame11FileName DB 'frame11.bin', 0
frame12FileName DB 'frame12.bin', 0
frame13FileName DB 'frame13.bin', 0
frame14FileName DB 'frame14.bin', 0
frame15FileName DB 'frame15.bin', 0
frame16FileName DB 'frame16.bin', 0
frame17FileName DB 'frame17.bin', 0
frame18FileName DB 'frame18.bin', 0
frame19FileName DB 'frame19.bin', 0
frame20FileName DB 'frame20.bin', 0

将所有 ASCIIZ 文件名存储在长度相同的记录中。

这里的意思是前9位用额外的零填充。记录大小变为 12.

frameFileName DB 'frame1.bin', 0, 0
              DB 'frame2.bin', 0, 0
              DB 'frame3.bin', 0, 0
              DB 'frame4.bin', 0, 0
              DB 'frame5.bin', 0, 0
              DB 'frame6.bin', 0, 0
              DB 'frame7.bin', 0, 0
              DB 'frame8.bin', 0, 0
              DB 'frame9.bin', 0, 0
              DB 'frame10.bin', 0
              DB 'frame11.bin', 0
              DB 'frame12.bin', 0
              DB 'frame13.bin', 0
              DB 'frame14.bin', 0
              DB 'frame15.bin', 0
              DB 'frame16.bin', 0
              DB 'frame17.bin', 0
              DB 'frame18.bin', 0
              DB 'frame19.bin', 0
              DB 'frame20.bin', 0

您可以通过计算其在 table 中的偏移量并将其添加到 table 的开头来引用正确的文件名。 address = start + index * recordsize.

如果从零开始工作,第一个文件名的索引为 0,第 20 个文件名的索引为 19,则任何特定文件名的有效地址都从以下位置获得:

; BX is file index [0,19]
mov  ax, 12                  ;
mul  bx                      ; In 8086 there's no "IMUL BX, 12"
mov  bx, ax                  ;
lea  bx, [frameFileName + bx]

或者如果您不想破坏 DX 并且您不需要超过 255 个文件:

; AL is file index [0,19]
mov  ah, 12
mul  ah
mov  bx, ax
lea  bx, [frameFileName + bx]

使用您用 2 位数字填写的模板。

这将节省很多 space,尤其是当文件数量增加时。它甚至可能需要 3 或 4 位数字。

frameFileName DB 'frame??.bin', 0

...

; AL is file index [1,20]
aam                          ; Divides AL by 10, Use this only if AL=[0,99]
add  ax, 3030h               ; Convert to text
xchg al, ah
mov  bx, offset frameFileName
mov  [bx+5], ax