8086 assembly exercise notes

1. If there is a string (ending with the character '$') stored in the STRING unit, please implement the following tasks:

(1) Program to count the length of the string (does not contain the character '$', and assumes the length is two bytes).

(2) Put the length of the string in the STRING unit, and move the entire string down two units.

(1)

1  DATA SEGMENT
 2      STRING DB ' HELLO ASM$ ' 
3  DATA ENDS
 4  CODE SEGMENT 
 5      ASSUME CS: CODE, DS: DATA ; otherwise it will lead to invalid operation 
6     ; LEN AX, STRING; why not 
7     ; MOV AX , OFFSET STRING is gross No way 
8     LEA SI, STRING
 9     ; here how to get the value 
10 in the physical address of the memory     ; the offset address is stored in SI, square brackets [] need to be used to distinguish register addressing, the default segment when using SI, DI, BX The base address is DS, when using BP (stack), the segment base address is SS 
11  AGAIN: 
12     MOV AL, [SI] ;Here AL stores a value, not an address. The next character only needs inc si.        
13     INC SI
 14     CMP AL, ' $ ' 
15     JNZ ACTION
 16     JZ OUTPUT
 17  ACTION: 
18      INC DL
 19      JMP AGAIN
 20  OUTPUT:  
21      ; Note that it cannot be output directly, remember to turn the ascll code first. 
22      ADD DL, 30H
 23      MOV AH, 02H
 24      INT 21H
 25 CODE ENDS

Initial register value: After the end:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325473955&siteId=291194637