我需要帮助在装配中构建一个不成比例的三角形,并且 if/else 语句也在装配中

I need help building an unproportional triangle in assembly and if/else statment also in assembly

所以,我有这段代码用于汇编中的三角形,问题是我只被允许构建比例三角形,如 75*75 等。我需要构建一个 135*40 并且在某些时候我会在一个圆圈中一次删除 2 个像素,有人可以帮助我吗?

    mov cx, 176              ;coluna
    mov dx, 80             ;linha
    mov [cont], 75
     ciclo2:                   
     mov al,[cont]
     mov [cont2], al            ; cont2 will be initialized with 75, 74, ...
    ciclo1:                   
    ;ativa um pixel
    mov ah, 0Ch              
    mov al, 4                      
    mov bh, 0                
    int 10h
    dec cx
    dec byte [cont2]
    jnz ciclo1
mov cx, 176
dec dx
dec byte [cont]
jnz ciclo2 

填充的 135*40 像素三角形中每条线之间的宽度差不是整数。如果愿意,可以使用浮点运算,但更简单的方法是使用定点运算。也就是说,将值按一定位数缩放(例如 8,这意味着乘以 256)。
最底部的行将是 135 像素宽,因此从 135 * 256 == 34560 的值开始。内循环的循环计数将是该字的高字节,即 34560 >> 8 == 34560 / 256 == 135。然后我们在内循环后从这个值中减去(135 / 40) * 256 == 864,这样下一行会稍微短一些:

; cont2_init is a word variable (2 bytes)
mov cx, 160               ;coluna
mov dx, 80               ;linha
mov [cont], 40
mov [cont2_init],34560  ; 34560 = 135 * 256
cicloc2:                   ;ciclo que repete a linha até fazer um quadrado
mov al,[cont2_init+1]        ; get the whole part of the fixed-point number
mov [cont2], al
        cicloc1:                    ;ciclo que cria a linha
        ;ativa um pixel
        mov ah, 0Ch               ;desenha nos pixeis do ecra
        mov al, 4                 ;determina a cor
        mov bh, 0                 ;numero de pagina grafica
        int 10h
        dec cx
        dec [cont2]
        jnz cicloc1
mov cx, 160
dec dx
sub [cont2_init],864  ; 864 = (135 / 40) * 256
dec [cont]
jnz cicloc2

对于一个 135 像素宽、40 像素高的三角形,第 r 行的宽度为 (135 * r) / 40。所有整数数学;不需要浮点或定点数学。如果在除法之前进行乘法,那么不会丢失数字。

只需替换:

mov al,[cont]
mov [cont2], al

作者:

mov al,[cont]   ; AL = row
mov bl,135
mul bl          ; AX = AL * BL = row * 135
mov bl,40
div bl          ; AL = AX / BL = (row * 135) / 40
mov [cont2], al

备注:

  • 小心高度>宽度的三角形;在您到达顶行之前,我的计算将达到零,这将导致您绘制一行 256 像素。您必须在进入循环之前测试零以防止出现这种情况。
  • 对于 > 255 的尺寸,需要进行更多调整。
  • div 轮 'down'(接近零);如果您更喜欢四舍五入到最接近的整数,请尝试 ((135 * r) + (40 / 2)) / 40。只需 add ax,20muldiv.
  • 抱歉,我还没有测试。