簡體   English   中英

在 MASM 8086 程序集中讀取多個文件

[英]Reading multiple files in MASM 8086 Assembly

我想在 MASM 中制作一個 animation,我一直在這樣做。 我如何使這更有效? 就像把它變成一個字符串數組? 以及如何在遞增時僅使用單個地址來訪問它? 我真的需要它,因為在主 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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM