Exercise One: In the three-word unit starting from si, there are unsigned numbers. It is required to add these three numbers, and the result is stored in the next unit.
Important: Note that it is an unsigned number. During the addition, as long as CF generates a carry, an overflow will occur.
DATA SEGMENT BUF DW XXH,YYH,ZZH SUM DW ?,? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX LEA SI,BUF LEA DI,SUM MOV AX,[SI] ADD AX,[SI+2] MOV [DI],AX MOV AX,0 ADC AX,O MOV [DI+2],AX MOV AX,[DI] MOV AX,[SI+4] MOV [DI],AX ADC [DI+2],0 MOV AH,4CH INT 21H COD ENDS END START
Exrcise Two: Try to write a program to write 256 units starting from address offset 100H to 00H, 01H, 02H, respectively. . . . , FFH.
We choose LOOP cycle.
DATA SEGMENT ORG 100H BUF1 DB 256 DUP(?) COUNT EQU $-BUF1 DATA ENDS STK SEGMENT STACK DB 100 DIP(?) STK ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STK START:MOV AX,DATA MOV DS,AX MOV SI,OFFSET BUF1 MOV CX,COUNT XOR AL,AL NEXT:MOV [SI],AL INC AL INC SI LOOP NEXT MOV AH 4CH INT 21H CODE ENDS END START
Exercise Three: Count the 0 elements, positive numbers, and negative numbers of the elements written in the above data block, and write the same i results in the last three units of the above data block.
SEGMENT the DATA ORG 100H BUF1 DB 00h, 01h, 02h ,,, FFH; suppose we now define COUNT EQU $ - BUF1 DB 3 DUP (? ) The DATA ENDS STK SEGMENT STACK DB 100 DIP (? ) STK ENDS CODE SEGMENT the ASSUME CS: CODE , DS: DATA, SS: STK START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET BUF1 MOV CX, COUNT XOR BX, BX; used to store positive and negative XOR DH, DH; used to store negative NEXT2: MOV AL, [SI] CMP AL, 0 JZ ZERO JS NEGAT INC BL JMP NEXT3 ZERO:INC DH NEGAT:INC BH NEXT3:INC SI LOOP NEXT2 MOV [SI],DH INC SI MOV [SI],BX MOV AH 4CH INT 21H CODE ENDS END START
Exercise Four: Transfer the contents of the 128 units starting from STRG1 to the units starting from STRG2.
Usually we generally choose the LOOP loop structure to build the program, but the MOVSB move string command can also be used for this.
DATA SEGMENT STRG1 DB XXH,XXH,XXH,,,,XXH SOUNT EQU $- STRG1 STRG2 DB 128 DUP(?) DDATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START:MOV AX,DATA MOV DS,AX MOV SI,OFFSET STRG1 LEA DI,STRG2 MOV CX,COUNT CLD REP MOVSB MOV AH,4CH INT 21H CODE ENDS END START
To be continued, to be continued ...