Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 二维像素阵列的组装_Arrays_Assembly_Pixels - Fatal编程技术网

Arrays 二维像素阵列的组装

Arrays 二维像素阵列的组装,arrays,assembly,pixels,Arrays,Assembly,Pixels,我怎么能在组装中做这样的事情?DOS 16位图形模式 int start_x=1, start_y=1; for(int i=0; i<8; i++){ for(int j=0; j<8; j++){ if(T34[i][j]==1) put_colour_pixel(start_x+i, start_y+j); else put_black_pixel(start_x+i, start_y+j); } } /////////////

我怎么能在组装中做这样的事情?DOS 16位图形模式

int start_x=1, start_y=1;
for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
        if(T34[i][j]==1) put_colour_pixel(start_x+i, start_y+j);
        else put_black_pixel(start_x+i, start_y+j);
    }
}
///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// 我的新代码:

    segment .data

    segment .code
..start:
    mov ax, 13h 
    int 10h               ; switch to 320x200 mode

    mov ax, 0a000h        ; The offset to video memory
    mov es, ax            ; We load it to ES through AX,
                          ; because immediate operation
                          ; is not allowed on ES

;;;;;;;;;;;;;;;;;;;;;;

       mov di, T34
       mov si, 8
;------------------------------------
P1:    mov bp, 8

;----------------
P2:    cmp BYTE[di], 1
       jnz short NOHIT

NOHIT: ; increase the x position

        push ax
       push bx
       push cx
       mov ax,si ;Y
       mov bx,bp ;X
       mov dl, 1 ; here I should take '0' or '1' from table
       call putpixel
       pop cx
       pop bx
       pop ax

       inc di  ; increase offset address of array
       dec bp
       jnz P2
;-------------
       ; increase the y position + substract 8 from x position
       dec si
       jnz P1
;------------------------------------


;;;;;;;;;;;;;;;;;;;;;;;;;

    xor ah, ah
    int 16h               ; keyboard (wait for key)

    mov ax, 3
    int 10h               ; go to text mode

    mov ax, 4c00h
    int 21h               ; return to DOS, exit code 0

;;;;;;;;;;;;;;;;;;;;;

putpixel:
    push dx               ; mul changes dx too
    mov cx, 320
    mul cx                ; multiply Y (ax) by 320 (one row)
    add ax, bx            ; and add X (bx) (result= dx:ax)
    mov di, ax
    pop dx
    mov [es:di], dl       ; store color/pixel
    ret

;;;;;;;;;;;;;;;;;;;;;;

T34 DB 1,1,1,1,1,1,1,1
    DB 1,0,0,0,0,0,0,0
    DB 1,0,0,0,0,0,0,0
    DB 1,0,0,0,0,0,0,0
    DB 1,1,1,1,1,1,1,1
    DB 1,0,0,0,0,0,0,0
    DB 1,0,0,0,0,0,0,0
    DB 1,1,1,1,1,1,1,1
我已经改变了顺序,现在它正在左角画正方形(正如我所预料的)。我把订单改好了吗? 我想那封信会有转机的,但这对我来说不是问题。我可以稍后再修

现在我应该转到表中的“0”或“1”并设置颜色。哪个寄存器有“0”或“1”

所以我对颜色有很大的问题。 我试过这个,但我有错误。我已尝试设置颜色黑色(0)或蓝色(1)

所以我不知道如何解决它:(我尝试了不同的可能性和北上的工作

       mov di, T34
       mov si, 8
;------------------------------------
P1:    mov bp, 8
;----------------
P2:    cmp BYTE[di], 1
       jnz short NOHIT

       ; save used REGISTER
       ; load register with the X,Y position and color
       call putpixel
       ; get back the saved Register

NOHIT: ; increase the x position
       inc di  ; increase offset address of array
       dec bp  ; decrease counter and set zeroflag if register is zero
       jnz P2  ; jump if zeroflag is not set
;-------------
       ; increase the y position + substract 8 from x position
       dec si
       jnz P1
;------------------------------------
也可以使用0为循环启动计数器以增加计数器,但如果要从0到8运行循环,则需要一条比较指令来离开循环。数组内的偏移地址是独立指向的,与计数器没有关系

只要稍加修改(在代码中添加一条跳转指令并进行第二次调用),如果数组的字节为0,也可以设置一个黑色像素。但我认为这种简单的嵌套循环形式在第一次使用时更容易理解

编辑:现在它与NASM兼容


Edit2:如果使用了许多参数,那么将x,y坐标存储到已知的ram位置以便在循环内部修改和重新加载可能更简单

我们的ram位置:

Color DB ?  ; define byte
X_Pos DW ?  ; define word
Y_Pos DW ?
显示如何访问内存位置(默认段为DS)的示例:


编辑3:

mov dl,  ax; here is error, here I set the colour
不可能将8位寄存器与16位寄存器混合使用。 注:

现有指示包括:

mov dl,  al
mov dl,  ah
mov dx,  ax
movzx dl, ax

“…变量。我应该在哪里存储…”使用寄存器。处理速度更快,寻址更容易。我会尝试,但我不确定是否有足够的寄存器来存储第一个开始x、开始y、循环计数(因为in-for是一种好方法还是另一种方法?),像素x,像素y。数组呢?我如何访问这个?或者我应该使用32位访问这个?我很抱歉有这么多问题,但我刚开始使用寄存器要经济。堆叠那些不经常访问的寄存器,以释放它们以供替代使用。我编辑了我的问题。当我的一个循环工作时,我会尝试另一个循环内部。这段代码有什么问题吗?你的putpixel例程修改ax寄存器这一行:mov di,OFFSET T34和这:P2:cmp BYTE PTR[di],1告诉我在操作数之后应该是sth。我不知道为什么。所以我无法编译它。我使用nasm 16 DOS。对于nasm,请删除“OFFSET”并删除“PTR”,它只适用于MASM。它是好的Y和X?mov ax,si;Y mov bx,bp;X就像C语言中的“i”和“j”?它不起作用。即使我尝试放置单个像素,例如10,10。它只进入P1循环,而不进入P2循环。请发布所有新代码,让我们看看发生了什么。
mov [X_Pos], ax
mov [X_Pos], bx  
mov [Color], dl  
mov ax, [X_Pos]
mov bx, [Y_Pos]
mov dl, [Color]

mov WORD[X_Pos], 10
inc WORD[X_Pos]
sub WORD[X_Pos], 8
mov BYTE[Color], 4
inc BYTE[Color]
mov dl,  ax; here is error, here I set the colour
AX = AL+AH
DX = DL+DH
mov dl,  al
mov dl,  ah
mov dx,  ax
movzx dl, ax