Added stage 2 of the assessment with stack management

Changed Stage 1 to use full registers and the si register instead of splitting them
This commit is contained in:
iDunnoDev
2022-11-05 23:34:34 +00:00
committed by iDunnoDev
parent d7f3c20324
commit fe2e14921a
19 changed files with 585 additions and 60 deletions

View File

@ -39,7 +39,6 @@ cons_writeline:
ret
# Added Write Hex and Int functions to help with debugging
HexChars: .ascii "0123456789ABCDEF"
cons_write_hex:
@ -62,7 +61,7 @@ cons_write_int:
cmpw $0, %ax
jge getdigit
xor %ax, %ax
xor %ax, %ax # Added to handle signed numbers, it adds the minus and then neg's the number
movb $0x0E, %ah
movb $0x2D, %al
int $0x10
@ -85,13 +84,14 @@ getdigit:
IntBuffer: .string " "
# Draw Line function
cons_draw_line:
movw $0, err # Make sure that err starts at 0
movw %ax, (x0) # Move the initial vars from the registers to static memory
movb %cl, (y0)
movw %bx, (x1)
movb %ch, (y1)
movb %dl, (color)
movw %bx, (y0)
movw %cx, (x1)
movw %dx, (y1)
movw %si, (color)
movw x1, %cx # Load x1 and y1 into the registers
movw y1, %dx
@ -102,16 +102,17 @@ cons_draw_line:
cons_line_check_x:
movw x0, %cx # Load x0 into register cx so we can manipulate this value to plot each pixel
movw $1, (sx) # Preload x slope with 1
cmp x1, %cx # Check if x1 is less than x0 and we can move to y
movw $1, (sx) # Preload the x slope with 1
cmp x1, %cx # Check if x0 is less than x1 and we can move to y
jl cons_line_check_y
negw sx # if x1 is greater than we need to flip the slope and the x delta values
negw deltax
negw sx # If x1 is greater than we need to flip the slope and the x delta values
negw deltax # Flipping the deltax here saves us from having to have an abs function because if
# x0 was greater than x1 we know we have a negative delta value and we flip it to pos
cons_line_check_y:
movw y0, %dx # Load y0 into register dx so we can manipulate this value to plot each pixel
movw $1, (sy) # Preload y slope with 1
cmpw y1, %dx # Check if y1 is less than y0 and we can start our plotting
movw $1, (sy) # Preload the y slope with 1
cmpw y1, %dx # Check if y0 is less than y1 and we can start our plotting
jl cons_line_prep_loop
negw sy # if y1 is greater than we need to flip the slope y and delta y values
negw deltay
@ -136,7 +137,7 @@ cons_line_loop_start:
jmp cons_line_loop_end # if both x's and y's are equal then we can end the function
cons_line_loop_next_point:
movw err, %ax # Load err into ax so that we can multiply it
movw err, %ax # Load err into ax so that we can change it
add %ax, %ax # e2 is 2 * err, so we can just add err to itself
cons_line_loop_move_y_point:
@ -170,75 +171,75 @@ draw_start:
int $0x10
xor %ax, %ax
movw $50, %ax # Plot a line, ax = x0, bx = x1, cl = y0, ch = y1, dl = color
movb $50, %cl # the X values require a full register but the y's only require a byte since the max value is 200
movw $160, %bx
movb $55, %ch
movb $12, %dl # The Color also only requires a byte
movw $50, %ax # Plot a line, ax = x0, bx = y0, cx = x1, dx = y1, si = color
movw $50, %bx
movw $160, %cx
movw $55, %dx
movw $12, %si # The Color using the si counter because we dont have enough normal registers
call cons_draw_line
# Draw the rest of the lines
movw $160, %ax
movb $55, %cl
movw $90, %bx
movb $150, %ch
movb $11, %dl
movw $55, %bx
movw $90, %cx
movw $150, %dx
movw $11, %si
call cons_draw_line
movw $90, %ax
movb $150, %cl
movw $50, %bx
movb $50, %ch
movb $14, %dl
movw $150, %bx
movw $50, %cx
movw $50, %dx
movw $14, %si
call cons_draw_line
movw $10, %ax
movb $10, %cl
movw $310, %bx
movb $10, %ch
movb $9, %dl
call cons_draw_line
movw $310, %ax
movb $10, %cl
movw $310, %bx
movb $190, %ch
movb $10, %dl
call cons_draw_line
movw $310, %ax
movb $190, %cl
movw $10, %bx
movb $190, %ch
movb $13, %dl
movw $310, %cx
movw $10, %dx
movw $9, %si
call cons_draw_line
movw $310, %ax
movw $10, %bx
movw $310, %cx
movw $190, %dx
movw $10, %si
call cons_draw_line
movw $310, %ax
movw $190, %bx
movw $10, %cx
movw $190, %dx
movw $13, %si
call cons_draw_line
movw $10, %ax
movb $190, %cl
movw $10, %bx
movb $10, %ch
movb $15, %dl
movw $190, %bx
movw $10, %cx
movw $10, %dx
movw $15, %si
call cons_draw_line
movw $75, %ax
movb $150, %cl
movw $250, %bx
movb $110, %ch
movb $1, %dl
movw $150, %bx
movw $250, %cx
movw $110, %dx
movw $1, %si
call cons_draw_line
movw $210, %ax
movb $30, %cl
movw $300, %bx
movb $150, %ch
movb $6, %dl
movw $30, %bx
movw $300, %cx
movw $150, %dx
movw $6, %si
call cons_draw_line
movw $180, %ax
movb $180, %cl
movw $170, %bx
movb $20, %ch
movb $3, %dl
movw $180, %bx
movw $170, %cx
movw $20, %dx
movw $3, %si
call cons_draw_line
endless_loop: # Loop forever more
@ -258,4 +259,4 @@ sx: .word 0
sy: .word 0
err: .word 0
e2: .word 0
color: .byte 0
color: .word 0