首页 > 解决方案 > 在 MASM 8086 程序集中读取多个文件

问题描述

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

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

标签: arraysstringassemblyx86-16masm

解决方案


将所有 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

您可以通过计算其在表中的偏移量并将其添加到表的开头来引用正确的文件名。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 位数字的模板。

这将节省大量空间,尤其是在文件数量增加的情况下。它甚至可能需要 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

推荐阅读