简体   繁体   English

如何拒绝或反转内存地址

[英]How to deny or invert the memory address

I'm doing some tasks and I need to solve the following problem: I need to load with a descending table, this table starts at the value 0000 and ends with ffff, for example: 我正在执行一些任务,并且需要解决以下问题:我需要加载一个降序表,该表以值0000开始,以ffff结尾,例如:

Addres    value
0000      ffff
0001      fffe
0002      fffd
....      ....
....      ....
ffff      0000

My code: 我的代码:

mov ax,0000
mov bx,0000
not bx
mov ax,bx ; this is line 41
inc ax
dec bx
cmp ax,ffff
jne 41 
int 3

directly, this code does not work, does nothing. 直接,此代码不起作用,什么也不做。 I don't have great knowledge in assembly and I can't detect the error. 我没有汇编方面的丰富知识,也无法检测到错误。

Successive addresses store a single byte that can hold values from 0 to 255 . 连续地址存储一个字节,该字节可以保存0到255之间的值 For the values from 0 to FFFFh that you want to store, you would need 131072 bytes (65536*2). 对于要存储的从0到FFFFh的值,您将需要131072字节(65536 * 2)。 In 16-bit mode (real address mode) a memory segment can have 65536 bytes making your task a bit complicated! 在16位模式(实地址模式)下,一个内存段可以有65536个字节,这使您的任务有些复杂!

    cld
    xor     di, di    ; Address 0000h
    mov     ax, FFFFh ; Value
More:
    stosw
    dec     ax
    js      More

This will store 32768 descending word-values at offset addresses 0, 2, 4, 6, ... , 65534. 这将在偏移地址0、2、4、6,...,65534上存储32768个降序字值。
At this point you would have to change the ES segment register by adding 2048 to it. 此时,您必须通过将2048加上ES段寄存器来更改它。
Then continu with next code: 然后继续下一个代码:

    ; DI=0 AX=7FFFh 
More_:
    stosw
    dec     ax
    jnz      More_

A byte solution is possible however: 但是,可以使用字节解决方案:

    mov     bx, 0
    mov     al, 255
Next:
    mov     [bx], al
    inc     bx
    dec     al
    jnz     Next

    ; 0000  FF
    ; 0001  FE
    ; 0002  FD
    ;
    ; 00FE  01
    ; 00FF  00

A byte solution using 1 register: 使用1个寄存器的字节解决方案:

    xor     bx, bx
 ext:
    mov     [bx], bl
    not     byte ptr [bx]
    inc     bx
    test    bl, bl
    jnz     Next

    ; 0000  FF
    ; 0001  FE
    ; 0002  FD
    ;
    ; 00FE  01
    ; 00FF  00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM