Problems with BIOS delay function (INT 15h / AH = 86h)

狂风中的少年 提交于 2020-01-17 05:46:20

问题


I began studying assembly this year in my school, and we just started learning about pixels.

Our teacher gave us some code and told us to mess around with it, he also told us to try and implement delay in the code(ah=86h|int 15h), but when i tried to use it the location and colors of some pixels got changed, and i don't understand why

code: (just a piece of the code, there is some more there also get's ruined after the delay)

mov cx,  20

add [y], 2
mov dx, [y]

paint1RowOf10:

mov bh, 0h 
mov bx, cx

add [x], 1
mov cx, [x]

add [y], 4
mov dx, [y]

mov ax, [red]
mov ah,0ch 
int 10h 

    ; here is a delay part, it waits for 1 seconde
    ; from the help of assembly:
    ; INT 15h / AH = 86h - BIOS wait function. 
    ;CX:DX = interval in microseconds (these are notes from my teacher)

mov ah, 86h
mov cx, 1
mov dx, 2
int 15h 

mov cx, bx
loop paint1RowOf10    

This is the result http://prntscr.com/9a8lpw can you tell me why does this happen? because as far as i see, the pixels are supposed to go in one line, and not change colors.


回答1:


There is a weird fact, about int 15h ah=86h you also need to set al=0, unless it get an erratic behavior

Delay Code:

mov al, 0 mov ah, 86h mov cx, 1 mov dx, 2 int 15h

I discovered it with try-and-error method and I realize when al=0 it works.




回答2:


Try using a debugger to make sure all the registers still have the values you expect, after the int 10h system/BIOS call (whatever it is). I haven't checked docs, but it may clobber some other registers?

Or maybe your problem is:

mov ax, [red]
mov ah,0ch 
int 10h

Remember that ah is the high half of ax. So if you modify ah right after loading something into ax, it's YOUR code that modified your color value.


Also, code like

add [y], 2
mov dx, [y]

is horrible. Try to keep variables in registers when you can. If you need to spill some, try to avoid doing it with variables that change every time through the loop.

mov dx, [y] 
add dx, 2 
mov [y], dx

Would be somewhat better, because dx would come from the first load, not a chain of read-modify-write -> load. It is more instructions, which is why keeping important loop variables in memory is bad.



来源:https://stackoverflow.com/questions/34089884/problems-with-bios-delay-function-int-15h-ah-86h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!