Created
December 13, 2019 21:32
-
-
Save osamaadam/7ea5efadec749f796334e8b8383fbb3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include 'emu8086.inc' | |
org 100h | |
PRINT 'Enter the number of rows' | |
call PRINT_NEW_LINE | |
call SCAN_NUM | |
call PRINT_NEW_LINE | |
mov ax, 01 ; number to be printed | |
call PRINT_NUM_UNS | |
cmp cx, 01H ; terminate if number of lines == 1 | |
je TERMINATE | |
dec cx | |
mov ax, 00H | |
mov bx, 00H | |
ARRAY_GEN: | |
cmp arr1[bx], 0 ; determine the location of the last element of the last array | |
jz ARRAY_1ST | |
inc bx | |
inc bx | |
jmp ARRAY_GEN | |
ARRAY_2ND: | |
cmp arr1[bx], 0 | |
jz PRINT_ARRAY | |
mov ax, arr1[bx] | |
add ax, arr2[bx] | |
mov arr2[bx+2], ax | |
inc bx | |
inc bx | |
jmp ARRAY_2ND | |
ARRAY_1ST: | |
dec bx | |
dec bx | |
mov ax, arr1[bx] ; Move the last element of the top array | |
mov arr2[0], ax ; to the first column of the bottom array | |
mov bx, 0H | |
jmp ARRAY_2ND | |
PRINT_ARRAY: | |
call PRINT_NEW_LINE | |
mov bx, 0H | |
REPEAT: | |
cmp arr2[bx], 0 | |
jz COPY_ARR2 | |
mov ax, arr2[bx] | |
GOTOXY ch, DL | |
call PRINT_NUM_UNS | |
add ch, 0AH | |
inc bx | |
inc bx | |
jmp REPEAT | |
COPY_ARR2: | |
call ARRAY_COPY | |
mov bx, 0 | |
mov ch, 0 | |
dec cl | |
cmp cl, 0 | |
jz TERMINATE | |
jmp ARRAY_GEN | |
TERMINATE: | |
ret | |
;================ | |
DEFINE_SCAN_NUM | |
DEFINE_PRINT_NUM_UNS | |
NEW_LINE db 0AH, 0DH, '$' | |
arr1 dw 0001H, 000FH DUP(0) | |
arr2 dw 0001H, 000FH DUP(0) | |
TEMPA dw 0H | |
TEMPB dw 0H | |
TEMPC dw 0H | |
TEMPD dw 0H | |
;=================== | |
PRINT_NEW_LINE PROC | |
add DL, 01H | |
mov TEMPA, ax | |
mov TEMPD, dx | |
lea dx, NEW_LINE | |
mov AH, 09H | |
int 21H | |
mov ax, TEMPA | |
mov dx, TEMPD | |
ret | |
PRINT_NEW_LINE ENDP | |
;=================== | |
ARRAY_COPY PROC | |
mov TEMPA, ax | |
mov TEMPB, bx | |
mov ax, 0H | |
mov bx, 0H | |
COPY: | |
mov ax, arr2[bx] | |
mov arr1[bx], ax | |
inc bx | |
cmp bx, 0FH | |
jne COPY | |
mov ax, TEMPA | |
mov bx, TEMPB | |
ret | |
ARRAY_COPY ENDP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include 'emu8086.inc' | |
org 100h | |
PRINT 'Enter the number of rows' | |
call PRINT_NEW_LINE | |
call SCAN_NUM | |
call PRINT_NEW_LINE | |
mov ax, 01 ; number to be printed | |
call PRINT_NUM_UNS | |
cmp cx, 01H ; terminate if number of lines == 1 | |
je TERMINATE | |
dec cx | |
inc tempE | |
inc tempF | |
inc tempF | |
mov ax, 00H | |
mov bx, 00H | |
ARRAY_GEN: | |
shr bx, 1 | |
cmp bx, tempE | |
jz boundaryElement | |
shl bx, 1 | |
inc bx | |
inc bx | |
jmp ARRAY_GEN | |
boundaryElement: | |
shl bx, 1 | |
mov arr2[bx], 1 | |
jmp ARRAY_1ST | |
ARRAY_2ND: | |
cmp bx, 1 | |
jne notEqualOne | |
isNotEqualOne: | |
cmp bx, tempE | |
jz PRINT_ARRAY | |
shl bx, 1 | |
cmp bx, 0 | |
jz firstElement | |
mov ax, arr1[bx] | |
add ax, arr1[bx - 2] | |
mov arr2[bx], ax | |
inc bx | |
inc bx | |
jmp ARRAY_2ND | |
notEqualOne: | |
shr bx, 1 | |
jmp isNotEqualOne | |
firstElement: | |
inc bx | |
inc bx | |
jmp ARRAY_2ND | |
ARRAY_1ST: | |
shl bx, 1 | |
dec bx | |
dec bx | |
mov arr2[0], 1 | |
mov bx, 0H | |
jmp ARRAY_2ND | |
PRINT_ARRAY: | |
call PRINT_NEW_LINE | |
mov bx, 0H | |
REPEAT: | |
shr bx, 1 | |
cmp bx, tempF | |
jz COPY_ARR2 | |
shl bx, 1 | |
mov ax, arr2[bx] | |
GOTOXY ch, DL | |
call PRINT_NUM_UNS | |
add ch, 0AH | |
inc bx | |
inc bx | |
jmp REPEAT | |
COPY_ARR2: | |
shl bx, 1 | |
mov arr2[bx], 1 | |
call ARRAY_COPY | |
mov bx, 0 | |
mov ch, 0 | |
dec cl | |
inc tempE | |
inc tempF | |
cmp cl, 0 | |
jz TERMINATE | |
jmp ARRAY_GEN | |
TERMINATE: | |
ret | |
;================ | |
DEFINE_SCAN_NUM | |
DEFINE_PRINT_NUM_UNS | |
NEW_LINE db 0AH, 0DH, '$' | |
arr1 dw 0001H, 000FH DUP(0) | |
arr2 dw 0001H, 000FH DUP(0) | |
TEMPA dw 0H | |
TEMPB dw 0H | |
TEMPC dw 0H | |
TEMPD dw 0H | |
tempE dw 0H | |
tempF dw 0H | |
;=================== | |
PRINT_NEW_LINE PROC | |
add DL, 01H | |
mov TEMPA, ax | |
mov TEMPD, dx | |
lea dx, NEW_LINE | |
mov AH, 09H | |
int 21H | |
mov ax, TEMPA | |
mov dx, TEMPD | |
ret | |
PRINT_NEW_LINE ENDP | |
;=================== | |
ARRAY_COPY PROC | |
mov TEMPA, ax | |
mov TEMPB, bx | |
mov ax, 0H | |
mov bx, 0H | |
COPY: | |
mov ax, arr2[bx] | |
mov arr1[bx], ax | |
inc bx | |
cmp bx, 0FH | |
jne COPY | |
mov ax, TEMPA | |
mov bx, TEMPB | |
ret | |
ARRAY_COPY ENDP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment