- 1 year ago
How to make right drawing of rectangele and ellipse on ASM?
Creating the right drawing of a rectangle and ellipse using assembly language can be a complex task, as it involves manipulating graphics memory and understanding the specific graphics mode or framework being used. The approach can vary depending on the specific assembly language and graphics library you are working with.
Here's a simplified example in x86 assembly language using the DOS INT 10h interrupt to draw a rectangle and ellipse on the screen:
assembly.model small
.stack 100h
.data
x1 dw 50
y1 dw 50
x2 dw 150
y2 dw 150
.code
main proc
mov ax, @data
mov ds, ax
mov ax, 13h ; Set graphics mode (320x200, 256 colors)
int 10h
; Draw rectangle
mov ax, 0A000h
mov es, ax
xor di, di
mov cx, x2
sub cx, x1
mov dx, y2
sub dx, y1
mov ax, 0ch ; Color (12h = Red)
mov bh, 0 ; Page number (0 for the main screen)
call draw_rectangle
; Draw ellipse
mov cx, x1
add cx, x2
shr cx, 1 ; Calculate ellipse center X
mov dx, y1
add dx, y2
shr dx, 1 ; Calculate ellipse center Y
mov ax, 0Eh ; Color (0Eh = Yellow)
mov bh, 0 ; Page number (0 for the main screen)
call draw_ellipse
mov ax, 4C00h ; Exit to DOS
int 21h
draw_rectangle proc
push ax
push cx
push dx
push di
mov ax, cx
mov cx, dx
mov dx, ax
mov ax, 0
mov cx, dx
mov dx, di
int 10h
pop di
pop dx
pop cx
pop ax
ret
draw_rectangle endp
draw_ellipse proc
push ax
push bx
push cx
push dx
push di
push si
mov ax, cx
mov cx, dx
mov dx, ax
mov ax, 0
mov bx, dx
mov cx, si
mov dx, di
int 10h
pop si
pop di
pop dx
pop cx
pop bx
pop ax
ret
draw_ellipse endp
end main
This example uses the graphics mode 13h (320x200, 256 colors) and the INT 10h
interrupt to access the graphics video memory. The draw_rectangle
and draw_ellipse
procedures are called to draw the rectangle and ellipse, respectively.
Please note that this is a simplified example and may not work on modern systems. The specific approach and code structure may vary depending on the assembly language and graphics library you are using, as well as the specific requirements of your project.