Input and Output of Assembly Language Strings

Keywords: C

Variable Definition Pseudo Instruction

Definition: Variable definition pseudo instructions are used to allocate memory units for data and establish the relationship between variables and storage units.  

Statement Format: [Variable Name] Variable Definition Pseudo Instruction Operator 1 (Operator 2, Operator 3....)

Variable Definition Pseudo Instructions: DB (byte), DW (word), DD (double word), DQ (4 word), DT (5 word)

Personal Understanding: Understand variable definition pseudo instructions as data types (int, float...) in C language, that is, define data types

 

DUP statement format:

Variable Name, Variable Definition Pseudo Instruction Number, DUP (Repeated Content)

Note: If the repetition is a question mark (?) Representation: duplicate content is uncertain

offset statement format:

Offset variable name Explanation: The offset address of the variable name (i.e. the valid address)

DATA SEGMENT
INBUF  DB 6  ;INBUF For variable names, DB Pseudo instructions defined for variables, 6 for the number of elements;   
	   DB ?  ;Question mark (?) Represents reserved space, content is uncertain
;Note: Definition of Appeal INBUF The number of elements of is 6, but only 5 can be entered at most, because the last element is used to store the Enter key, because the string ends with the Enter key

INATV  DB 6 DUP(?)   ;The number of repetitions is 6, and the content of repetition is uncertain.
	   DB '$'  ;This sentence will'$'Defined as DB Type, string to'$'Ending
SHI    DW 10   ;Definition SHI by DW Types and up to 10 elements

MESS   DB  'please inter data:','$'   ;Define a string and save it MESS The definition of a string should be'$'End of Definition
	
DATA ENDS
;From the first sentence to this point, it's all about defining data break snippets.

;The following are definitions of code snippets
CODE SEGMENT
	ASSUME CS:CODE,DS:DATA   ;I read a lot more than I did before. DS: DATA,DS Store the current segment for the segment register( DATA)The starting address,
MAIN PROC FAR
START:
	MOV AX,DATA   ;Put the data in the data segment AX Register
	MOV DS,AX     ;take AX Data stored in DS Register
                  ;Note: Data in data segment cannot be moved directly to DS In Chinese, only from AX Register to DS

	mov dx,offset MESS   ;take MESS Valid Address Deposit dx in
	mov ah,09h           
	int 21h              ;These two statements represent output strings

	MOV DX,OFFSET INBUF  ;take INBUF Valid Address Deposit DX in
	MOV AH,0AH           
	INT 21H              ;These two codes mean waiting for you to enter a string

	MOV DL,0AH          
	MOV AH,2         
	INT 21H          ;The first three lines of code represent output'Line feed'        
	MOV DL,0DH
	MOV AH,2
	INT 21H          ;The first three lines represent output'Enter'

	MOV CL,INBUF+1   ;INBUF Address+1,point INBUF The second element,The second element represents the number of actual input characters
	MOV CH,0     ;Assign 0 to CH
	PUSH CX      ;take CX Value push stack (stacking)
	MOV BX,OFFSET INATV  ;take INATV Valid Address Deposit BX in
    MOV SI,4
DISC:	
    MOV DL,[BX][SI]   ;take BX Assign to DL
	MOV AH,2    
  	INT 21H     ;output DL Value
    DEC SI      ;SI Address-1
    LOOP DISC   ;Jump to DISC
 
	MOV DL,0AH
	MOV AH,2
	INT 21H     ;output'Line feed'
	MOV DL,0DH
	MOV AH,2
	INT 21H     ;output'Enter'

	MOV DL,INBUF+1
	ADD DL,30H
	INT 21H      ;Output Number of Actual Input Characters
	

	MOV AH,4CH
	INT 21H       ;Termination procedure
MAIN ENDP
CODE ENDS
	END START

 

Posted by RaheimSG on Mon, 30 Sep 2019 04:53:45 -0700