[英]How can I move an 8-bit address into a 16-bit register in x86 assembly?
[英]How to search for 8-bit value in a memory area and output the memory address? SBC86 Assembly
我必須為大學創建一個程序,用於在 memory 區域 C000H-CFFFH(SBC86 的監控程序)中搜索先前指定的 8 位值。 我們使用 i8086 模擬器。
但是我完全不知道我究竟是如何搜索 memory 區域和 output 找到的 memory 地址的值。
您可以使用REPNE SCASB
搜索已知值。 我們假設該值當前在AL
中(如果不是, mov
將其移動到那里。)
REPNE SCASB
(如果不相等則重復,掃描字符串字節)是這樣工作的:
AL
與byte ptr [es:di]
( di
指定的 memory 地址處的字節)進行比較,並相應地設置標志。di
(如果方向標志清除,否則減去 1)並從cx
減去 1,而不改變標志。AL = byte ptr [es:di]
或cx = 0
,則移至下一條指令。cld ;we want scasb to auto-inc
mov di,0C000h ;begin search at $C000 (assumes ES = segment you want to search)
mov cx,1000h ;repeat until $CFFF
repne scasb ;begin the search
此時,如果找到的話, di
將包含字節的地址。 但是,在這種情況下,您仍然需要一個條件分支,用於所需字節位於最后一個可能的 position 的極端情況。僅查看di
不會告訴您這一點。
cld
mov di,0C000h
mov cx,1000h
repne scasb
jne notFound
;your code for what happens when you find it goes here
jmp done
notFound:
;your code for what happens when you don't find it goes here
done:
ret
編輯:根據硬件規格將ds:si
的不正確用法更改為es:di
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.