у меня есть функция которая рисует прямоугольники: SECTION .text:CODE

EXPORT LCD_Fill_Rectangle_4

SSD2119_RAM_DATA_REG EQU 0x22 SSD2119_V_RAM_POS_REG EQU 0x44 SSD2119_H_RAM_START_REG EQU 0x45 SSD2119_H_RAM_END_REG EQU 0x46 SSD2119_X_RAM_ADDR_REG EQU 0x4E SSD2119_Y_RAM_ADDR_REG EQU 0x4F

REG_CMD EQU 0x130 ; 0xC4000000 /* RS = 0 / REG_DAT EQU 0x134 ; 0xC4000004 / RS = 1 */

; R0 - x ; R1 - y ; R2 - w ; R3 - h ; R4 - color ; R5 - end_aX ; R6 - end_start_aY ; R7 - REG_CMD ; R8 - REG_DAT ; R9 - SSD2119_..._REG ; R10 - w*h ; R11 - num_blocks (R10 / 4) ; R12 - remainder (R10 % 4)

LCD_Fill_Rectangle_4 PUSH {R4-R12, LR}

LDR R4, [SP];, #40] ; color --> R4

; end_aX = x + w - 1 ADD R5, R0, R2 SUB R5, R5, #1

; end_start_aY = ((y + h - 1) << 8) | y ADD R6, R1, R3 SUB R6, R6, #1 LSL R6, R6, #8 ORR R6, R6, R1

LDR R7, =REG_CMD LDR R8, =REG_DAT

; SSD2119_WRITE_CMD(SSD2119_V_RAM_POS_REG) LDR R9, =SSD2119_V_RAM_POS_REG STRH R9, [R7]

; SSD2119_WRITE_DAT(end_start_aY) STRH R6, [R8]

; SSD2119_WRITE_CMD(SSD2119_H_RAM_START_REG) LDR R9, =SSD2119_H_RAM_START_REG STRH R9, [R7]

; SSD2119_WRITE_DAT(x) STRH R0, [R8]

; SSD2119_WRITE_CMD(SSD2119_H_RAM_END_REG) LDR R9, =SSD2119_H_RAM_END_REG STRH R9, [R7]

; SSD2119_WRITE_DAT(end_aX) STRH R5, [R8]

; SSD2119_WRITE_CMD(SSD2119_X_RAM_ADDR_REG) LDR R9, =SSD2119_X_RAM_ADDR_REG STRH R9, [R7]

; SSD2119_WRITE_DAT(x) STRH R0, [R8]

; SSD2119_WRITE_CMD(SSD2119_Y_RAM_ADDR_REG) LDR R9, =SSD2119_Y_RAM_ADDR_REG STRH R9, [R7]

; SSD2119_WRITE_DAT(y) STRH R1, [R8]

; SSD2119_WRITE_CMD(SSD2119_RAM_DATA_REG) LDR R9, =SSD2119_RAM_DATA_REG STRH R9, [R7]

; R10 = w * h (number of pixels) MUL R10, R2, R3

MOV R11, R10 LSR R11, R11, #2 ; R11 = R10 >> 2 (R11 = R10 / 4) (number of blocks of 4 pixels) AND R12, R10, #3 ; R12 = R10 & 3 (R12 = R10 % 4) (remaining pixels)

; Determine loop based on R11 and R12

; R10 / 4 | R10 % 4 | ; 0 | >0 | loop_1 ; >0 | 0 | loop_2 ; >0 | >0 | loop_3

CMP R11, #0 BEQ check_remainder ; If R11 == 0, check R12

; R11 != 0 CMP R12, #0 BEQ loop_2 ; If R12 == 0, go to loop_2 B loop_3 ; Else go to loop_3

check_remainder ; R11 == 0, check R12 CMP R12, #0 BEQ end_fill ; If R12 == 0, skip (no pixels to write) B loop_1 ; Else go to loop_1

loop_1 ; Loop to write R12 pixels, one at a time write_1_pixel: STRH R4, [R8] ; Write pixel SUBS R12, R12, #1 BNE write_1_pixel B end_fill ; Go to the end after writing R12 pixels

loop_2 ; Loop to write R11 blocks of 4 pixels write_4_pixels: STRH R4, [R8] ; Write pixel 1 STRH R4, [R8] ; Write pixel 2 STRH R4, [R8] ; Write pixel 3 STRH R4, [R8] ; Write pixel 4 SUBS R11, R11, #1 BNE write_4_pixels B end_fill ; Go to the end after writing R11 * 4 pixels

loop_3 ; loop to write R11 blocks of 4 pixels write_4_pixels_loop3: STRH R4, [R8] ; Write pixel 1 STRH R4, [R8] ; Write pixel 2 STRH R4, [R8] ; Write pixel 3 STRH R4, [R8] ; Write pixel 4 SUBS R11, R11, #1 BNE write_4_pixels_loop3

; loop to write R12 remaining pixels

write_remaining_pixels: STRH R4, [R8] ; Write pixel SUBS R12, R12, #1 BNE write_remaining_pixels

end_fill POP {R4-R12, PC}

END

Мне нужно написать функцию на асемблере, которая рисует линию по алгоритму бразенхейма. У меня есть прототип этой функции на си:

void LCD_Draw_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t size, uint16_t color) { int deltaX = fabs(x2 - x1); int deltaY = fabs(y2 - y1); int signX = x1 < x2 ? 1 : -1; int signY = y1 < y2 ? 1 : -1; int error = deltaX - deltaY; for (;;) { LCD_Fill_Rectangle(x1, y1, size, size, color);

if (x1 == x2 && y1 == y2) break;

int error2 = error * 2;

 if (error2 > -deltaY)
 {
     error -= deltaY;
     x1 += signX;
 }

 if (error2 < deltaX)
 {
      error += deltaX;
      y1 += signY;
 }

}

}

Мне нужно, чтобы ты переписал эту функцию на асемблер под процессор armcm3