;************* lab 4, question 2********* ;*** Matz Lihi 300998630 *** Fuchs Dor 300687464*** .model small .stack 100h N_lines equ 6 ; The number of lines to be printed. .data rowCounter dw ? ; Counts the number of rows until N_lines charCounter dw ? ; Counts the number of characters in each line. numCharsInRow dw ? ; Specifies the number of characters to be printed in each line. .code start: mov ax,@data mov ds,ax ; Assign DS the beginning of the data segment in memory. mov ax, 3 int 10h ; Display output to the console. mov ax, 0b800h mov es, ax ; es points to the beginning of the console output segment. mov ax, 0140h ; Choose certain design to the rhombus. mov dx, 80 ; Begin the rhombus display in the middle of the first row. call RhombusProc ; Call the procedure which displays the rhombus. mov ax, 1203h ; Choose certain design to the rhombus. mov dx, 860 ; Begin the rhombus display somewhere in the screen. call RhombusProc ; Call the procedure which displays the rhombus. mov ah,4ch ; Return control to the operating system. int 21h ; Exit the program. RhombusProc: mov si,dx ; We use SI register as our offset register to the console. mov rowCounter, 0 ; In each call to the procedure we initialize the variables... mov numCharsInRow, 1 ; ... we use in drawing the rhombuses. drawRhombus: ; This label start the region in the procedure which actually draws the rhombus. mov charCounter, 0 ; Initailize the character counter for each new line. innerLoop: mov es:[si],ax ; Display character to the screen. add si,2 inc ah inc charCounter ; Increase the character counter in each iteration. mov cx, numCharsInRow cmp cx, charCounter jnz innerLoop ; Return to the inner loop in case not all the chars have been printed in the line. inc rowCounter ; Increase the rows counter. add si, 160 ; Move to the next line. sub si, charCounter sub si, charCounter ; Go backwards to create the diagonal shape. mov cx, N_lines ; Calculate the remaining number of rows so we know whether we are in the upper... sub cx, rowCounter ; ...part of the rhombus or the lower part. ; cmp cx, rowCounter ; Compare the number of rows printed thus far to the number of rows remaining. jbe drawLowerRhombus ; Draw the upper part in case we have not reached the rhombus' middle row. jmp drawUpperRhombus ; Otherwise, draw the rhombus' lower part. drawLowerRhombus: add si, 4 ; Add 2 places to the console output location. sub numCharsInRow, 4 ; Reduce the number of chars by 4 (2 added later in drawUpperRhombus) drawUpperRhombus: sub si, 2 ; Reduce 1 place from the console output location so it will have a diagonal shape. add numCharsInRow, 2 ; Add 2 chars to be printed in the next line. cmp numCharsInRow, 1 ; Check whether we reached the last character in the rhombus shpae. jne continue ; if not, go to 'continue'. mov rowCounter, N_lines ; In case there is an EVEN number of rows to draw, we 'fix' rowCounter so that it will contain ; the initial rows number. continue: cmp rowCounter, N_lines jbe drawRhombus ; Return to drawing the rhombus in case not all lines have been printed. ret end