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:
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 . For the values from 0 to FFFFh that you want to store, you would need 131072 bytes (65536*2). In 16-bit mode (real address mode) a memory segment can have 65536 bytes making your task a bit complicated!
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.
At this point you would have to change the ES
segment register by adding 2048 to it.
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.