Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assembly 8086 code for some reason doesn\'t work. It is supposed to draw an

ID: 662540 • Letter: T

Question

This assembly 8086 code for some reason doesn't work. It is supposed to draw any shape on screen inside a frame. I am very new to Assembly and would really appreciate help.

.model small
.stack 0100h
.data

.code

program:
main proc
jmp begin

; program to draw a shape.
mode      db 18       ;740 x 580.
xstart    dw 100
ystart    dw 100
xend      dw 640
yend      dw 480
colour    db 1        ;blue.
   
begin:
mov ah, 00            ;sub_function 0.
mov al, mode          ;selecting mode 18.
int 10h               ;calls the graphic interrupt.
mov al, colour        ;color goes in al.
mov ah, 0ch
mov cx, xstart        ;starts drawing the lines on x.
  
drawhorizontal:
mov dx, yend          ;putting point at the bottom.
int 10h
mov dx, ystart        ;putting point in the top.
int 10h
inc cx                ;moves to next point.
cmp cx, xend          ;yet checks if it's the end.
jnz drawhorizontal

drawvertical:           ;(the y value is already ystart.)
mov cx, xstart        ;plotting on left-side.
int 10h
mov cx, xend          ;plotting on right side.
int 10h
inc dx                ;moves down to the next point.
cmp dx, yend          ;checks for the end.
jnz drawvertical
  
readskey:
mov ah, 00
int 16h               ;waits for the keypress.
   
finish:
mov ah, 00            ;again the subfunction 0.
mov al, 03            ;the text mode-3.
int 10h               ;calls the int.
mov ah, 04ch
mov al, 00            ;finishes the program.
int 21h

main endp
end program

Explanation / Answer

Shape Interface (Shape.hhf)

Shape Implementation (Shape.hla)

Rectangle Interface (Rectangle.hhf)

Rectangle Implementation (Rectangle.hla)

========================================================================================

Output

  type Shape:class     var x:int32;     var y:int32;     procedure create; @returns("esi"); @external;     procedure getX; @returns("eax"); @external;     procedure getY; @returns("eax"); @external;     method setX(newx:int32); @external;     method setY(newy:int32); @external;     method moveTo(newx:int32; newy:int32); @external;     method rMoveTo(deltax:int32; deltay:int32); @external;     method draw; @abstract;  endclass;