【问题标题】:A Bresenham algorithm implementation[NASM]Bresenham 算法实现[NASM]
【发布时间】:2013-11-12 12:38:10
【问题描述】:

我正在开发一个可以绘制随机形状的 nasm 程序。我从这段代码开始,但每次编译时,我都会收到错误

bresen.asm:8: 错误:操作数 1 后应有逗号

这里是代码::

segment stack stack
        resb 100 ;declares a stack segment containing 64 bytes of uninitialised stack space, and points stacktop at the top
stacktop:

        segment data

        dex dw 0
        dy dw 0
        x_add dw 0
        y_add dw 0
        maxd dw 0
        act_dx dw 0
        act_dy dw 0
        c dw 0
        x1 dw 0
        y1 dw 0
        x2 dw 0
        y2 dw 0

        segment code
start:
        mov ax,data
        mov ds,ax
        mov ax,stack
        mov ss,ax
        mov sp,stacktop
          mov bp,stacktop

        ;init finished

        mov ah,0h
        mov al,13h
        int 10h

        ;screen set

        mov ax,word 200
        push ax          ;y2
        mov ax,word 50
        push ax          ;x2
        mov ax,word 20
        push ax          ;y1
        mov ax,word 65
        push ax          ;x1
        call line

        ;line(x1,y1,x2,y2)

        xor ax,ax
        int 16h

        ;wait key

        mov ah,0
        mov al,3
        int 10h

        ;go back to text mode

        mov ah,4ch
        int 21h

        ;end

line:
        push bp
        mov bp,sp
        mov ax,[bp+4] ;<-1 here
        mov [y2],ax
        mov ax,[bp+6]
        mov [x2],ax
        mov ax,[bp+8]
        mov [y1],ax
        mov ax,[bp+10]
        mov [x1],ax

        ;init-line end here!!!

        mov ax,[x2]
        sub ax,[x1]
        cmp ax,0
        jnl abs1
        neg ax
abs1:   mov [dex],ax

        ;dex=abs(x2-x1)

        mov ax,[y2]
        sub ax,[y1]
        cmp ax,0
        jnl abs2
        neg ax
abs2:   mov [dy],ax

        ;dy=abs(y2-y1)

        mov ax,[x1]
        cmp ax,[x2]
        jl min
        mov [x_add],word -1
        jmp end
min:    mov [x_add],word 1
end:
        ;if (x1>x2)

        mov ax,[y1]
        cmp ax,[y2]
        jl min2
        mov [y_add],word -1
        jmp end2
min2:   mov [y_add],word 1
end2:
        ;if (y1>y2)

        mov ax,[dy]
        cmp ax,[dex]
        jl min3
        mov ax,[dy]
        mov [maxd],ax
        jmp end3
min3:   mov ax,[dex]
        mov [maxd],ax
end3:

        mov cx,[maxd]
here:   mov ax,[dy]
        add [act_dy],ax
        mov ax,[act_dy]
        cmp ax,[maxd]
        jl next
        mov ax,[maxd]
        sub [act_dy],ax
        mov ax,[y_add]
        add [y1],ax
next:   mov ax,[dex]
        add [act_dx],ax
        mov ax,[act_dx]
        cmp ax,[maxd]
        jl next2
        mov ax,[maxd]
        sub [act_dx],ax
        mov ax,[x_add]
        add [x1],ax
next2:  call plot
        loop here
        mov sp,bp
        pop bp
        ret 8

plot:
        push ax
        push bx
        push cx
        push dx
        mov ah,0ch
        mov dx,[y1]
        mov cx,[x1]
        mov al,0d0h     ;change this to change the point-color
        mov bh,0h
        int 10h
        pop dx
        pop cx
        pop bx
        pop ax
        ret 

我试图找出原因,但它让我停滞了很长时间。如有任何反馈或疑问,我将不胜感激。

【问题讨论】:

    标签: assembly x86 nasm bresenham


    【解决方案1】:

    DY 是 NASM 语法中的指令,因此不能将其用作符号名称。

    【讨论】:

    • 谢谢。我对此进行了更改,但在那之后,我现在面临以下错误:> bresen.asm:1:警告:在声明@ 987654322@stack'时忽略了未知的部分属性“堆栈”:归零> bresen。 asm:22: error: symbol data' undefined &gt;bresen.asm:24: error: symbol stack' undefined 我使用的是 [dey] 而不是 [dy]
    • 您使用的是哪种输出格式。 AFAIK,segment name-f obj 有效。
    • 我使用的是默认命令; -f elf bresen.asm 然后使用 gcc 链接,最后运行 \bresen 希望能回答你的问题。
    • 嗯,你的目标是哪个操作系统?
    • Linux - 在 Ubuntu 上运行。我已经安装了 gcc 编译器。
    猜你喜欢
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 2011-06-08
    • 1970-01-01
    相关资源
    最近更新 更多