As an exam-type course design, it is indeed difficult to scale down the usage of various memory, stack usage, function design, and calling techniques learned earlier, the use of the transfer function (two errors in JMP and jczx + loop were made in the design of this project, and I was very impressed). After six hours of efforts today, we finally achieved a smooth implementation. The DTOC function does not end with 0 as in the previous test to facilitate the output of data in the whole row. The overall implementation is not affected here. Not to mention, the above code shown in the figure is due to errors in JMP and loop usage.
Assume Cs: code data segment dB '000000', '000000', '000000', '000000', '000000', '000000 ', '000000' dB '000000', '000000', '000000', '000000', '000000', '000000', '000000' dB '000000 ', '20140901', '20160901', '20160901' dd 1992, 22, 1993, 1994, 2391995, 5937000, 9, 13, 28, 38, 130,223 DW 476,778,100, 1442, 2258,2793, 4037,5635 DW 8226,1 1542,14430, 15257,17800 data ends table segment dB 21 DUP (31 DUP (''), 0); 32 characters table ends code segment start :; output data to the table in the form of characters mov ax, table mov ds, ax mov Si, 0 mov ax, data mov es, ax mov BX, 0 mov CX, 21 mov Di, 0; Output row and column data mov DL, 0; column mov DH, 3; row S: Push CX; save CX push Si; save the start position of the output data source push DX; Save the row and column data mov ax, word ptr es: [BX] mov DS: [Si], ax; the first two mov ax, word ptr es: [bx + 2] Add Si, 2 mov DS: [Si ], Ax; two mov dx, ES: [bx + 86] After the output year; Add Si, 4 mov ax, ES: [bx + 84] at the upper divisor position; divisor low Add Si, 2 push ax push DX; output as string call DTOC mov CX, ES: [bx + DI + 168]; divisor Add Si, 8; the output is a string mov ax, CX mov dx, 0 call DTOC pop DX pop ax; the division result is calculated to ax, DX call divdw Add Si, 8 call DTOC; output all the data in the table row to pop DX Inc DH mov Cl, 00100100b pop Si call show_str Add Si, 32 Add Bx, 4 sub Di, 2 Pop CX loop s mov ax, 4c00h int 21 h DTOC:; function: Convert DWORD data A string of the decimal number. The string ends with 0. Note: For full-line output, a single word does not end with 0. Parameter: (ax) = 16-bit low word data; (dx) = 16-bit high word data; DS: Si points to the first string address ('0': 30 h, '9': 39 h) Push BX push CX push Si push di mov Di, 0; used to record the output character length dtoc_k: mov CX, ax jcxz dtoc_r mov CX, 10 call divdw mov BX, 30 h Add Bx, CX push BX; character into Stack, solve the problem of character output sequence Inc di JMP dtoc_k; correct the error of using loop dtoc_k, here it should be a dynamic loop dtoc_r:; character output stack mov CX, di jcxz dtoc_end dtoc_p: Pop BX; from high to low output stack mov DS: [Si], BL; note that only one Inc Si loop dtoc_p dtoc_end: Pop di pop Si p is output. Op cx pop bx ret divdw:; function: conducts Division operations without overflow. The divisor type is DWORD, And the divisor type is word. The result is DWORD. Parameter: (ax) = 16-bit low for DWORD data; (dx) = 16-bit high for DWORD data; (CX) = divisor; Return: (dx) = 16-bit high for the result, (ax) = 16-bit lower result, (CX) = remainder push BX; push DX should not put DX into the stack, which is the data to be input and output push di push Si; calculate the SI remainder di of 00ax/CX, then the remainder of 00dx/CX ex is dx, and then the remainder of dxdi/cx dx mov BX, DX mov dx, 0 Div CX mov Di, DX; remainder Max. cx-1 mov Si, ax; quotient Max. 0000 FFFF mov ax, BX mov dx, 0 Div CX; bx00/CX mov BX, ax; quotient Max. 0000 fff F; remainder DX Max. cx-1 mov ax, di Div CX; dxdi/CX Add Si, ax; quotient Max. 0000 FFFF, Si cannot overflow mov CX, DX mov dx, BX mov ax, Si pop di; pop DX pop bx ret show_str:; function: Use the specified color at the specified position; display a string ended with 0; parameter: (DH) = row number (0 ~ 24), (DL) = column number (0 ~ 79),; (CL) = color, DS: first address of the SI string; Return: No push ax push BX push CX push DX push es push Si; determine the output first offset position: BX mov ax, 0b800h mov es, ax mov Al, DH mov ah, 160 Mul Ah mov DH, 0 add ax, DX add ax, DX mov BX, ax mov ah, Cl; colors are stored in high mov CH, 0 show_str_s: mov Cl, DS: [Si] jcxz show_str_ OK mov Al, CL mov ES: [BX], ax Add Bx, 2 Inc Si JMP short show_str_s show_str_ OK: Pop Si pop es pop DX pop CX pop BX pop ax RET code endsend start