Assembly language (Wang Shuang) Chapter VII & sixth experiment

Chapter VII & assembly language experiment six

7.1 and and or instructions

and instructions, and logic instructions perform bitwise AND

mov al,01100011B
and al,00111011B

After executing al = 00100011B, by the instruction of the operation target corresponding bit may be set to 0, the other bits unchanged

or instructions, logic or instructions, bitwise OR operation

mov al,01100011B
or al,00111011B

After executing al = 01111011B, by the instruction of the operation target corresponding bit may be set to 1, the other bits unchanged

About 7.2 ASCII code

We put the information stored in the computer, it is necessary it is encoded into binary information, and the information will be stored in a computer display to us, it is necessary to decode, ASCII code is an encoding scheme

When editing text Press a key, this key information incoming PC, into the computer code stored in the memory 61H, 61H text editing software taken from memory, it is sent to the memory on the video card, the work in the text the graphics mode, the contents of display memory used to explain the rules of the ASCII code, 61H is treated as a character, a character driving the display graphics image drawn on the screen

7.3 Data given in characters

In assembler, with '......' manner specified character data in the form given by the compiler converting them to the corresponding ASCII code

assume cs:code,ds:date

data segment
	db 'unIX'
	db 'foRK'
data ends

code segment
	start: mov al,'a'
		   mov bl,'b'
		   
		   mov ax,4c00h
		   int 21h
code ends
end start

db 'unIX' equivalent 'db 75H, 6EH, 49H, 58H'

mov al, 'a' corresponds mov al, 61H

7.4 case conversion issues

The first string is converted to uppercase datasg, the second string into lowercase

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down (img-awc0M48Y-1583139213436) (C: \ Users \ Tianming Hao \ AppData \ Roaming \ Typora \ typora-user-images \ image-20200302130808763.png)]

The first method, observed lowercase ASCII value than the large capital letters ASCII value corresponding to 20H, but due to the lower case string both have uppercase, determines whether the required upper or lower case, but not learned compilation of statements by using judgment

The second method, from the point of view of ASCII code binary form, except bit 5 (counting from 0), the other bits are the same, so for a letter, regardless of uppercase lowercase, the first position 5 can be zero

assume cs:codesg,ds:datasg

datasg segment
	db 'BaSiC'
	db 'iNdOrMaTiOn'
datasg ends

codesg sgement
	start:	mov ax,datasg
			mov ds,ax
			
			mov bx,0
			
			mov cx,0
		  s:mov al,[bx]
		    and al,11011111B
		    mov [bx],al
		    inc bx
		    loop s
		    
		    mov bx,5
		    
		    mov cx,11
		 s0:mov al,[bx]
		 	or al,00100000B
		 	mov [bx],al
		 	inc bx
		 	loop s0
		 	
		 	mov ax,4c00h
		 	int 21h
codesg ends
end start

7.5 [bx + data]

A memory cell may be represented by [bx + idata], which offset address is (bx) + idata

The following instruction is equivalent to

mov ax,[bx+200]
mov ax.[200+bx]
mov ax,200[bx]
mov ax,[bx].200

Array processing with 7.6 [bx + idata] manner

Fill code codesg, the first string into a defined datasg uppercase, lowercase string into a second

The original method requires two cycles, but at the same cycle can be completed in

assume cs:code,ds:datasg

datasg segment
	db 'BaSiC'
	db 'MinIX'
datasg ends

codesg segment
	start:	mov ax,datasg
			mov ds,ax
			
			mov bx,0
			
			mov cx,5
		  s:mov al,[bx]
		    and al,11011111B
		    mov [bx],al
		    
		    mov al,[5+bx]
		    or al,00100000B
		    mov [5+bx],al
		    inc bx
		    loop s
		    
		    mov ax,4c00H
		    int 21H
codesg ends
end

Comparison of c and assembly language

C:a[i],b[i]

Compilation: 0 [bx], 5 [bx]

7.7 和 OF YOU

8086CPU si and di are similar in function and register bx, si, and di is divided into two 8-bit registers can not be used

3 the same set of instructions following features

mov bx,0
mov ax,[bx]

mov si,0
mov ax,[si]

mov di,0
mov ax,[di]

Di si and implemented with the string 'welcome to masm!' Copy back to its data area

assume cs:codesg,ds:datasg

datasg segment
	db 'welcome to masm!'
	db '................'
datasg ends

codesg sgement
	start:	mov ax,datasg
			mov ds,ax
			
			mov si,0
			
			mov cx,8
		  s:mov ax,0[si]
		    mov 16[si],ax
		    add si,2
		    loops
		    
		    mov ax,4c00h
		    int 21h
codesg ends
end start

7.8 [bx + si] 和 [bx_di]

[Bx + di] i.e. offset address (bx) + (si)

The following instruction is equivalent to

mov ax,[bx+si]
mov ax,[bx][si]

7.9 [+ bx + is idata] 和 [bx + of + idata]

[Bx + si + idata] 即 (x) + (yes) + idata

Common formats

mov ax,[bx+si+200]
mov ax,[bx+200+si]
mov ax,[200+bx+si]
mov ax,200[bx][si]
mov ax,[bx].200[si]
mov ax,[bx][si].200

7.10 flexible application of different ways of addressing

The first letter of each word in datasg paragraph to uppercase letters

assume cs:codesg,ds:datasg

datasg segment
	db '1. file         '	;每个字符串长度为16个字节,因为连续存放
	db '2. edit         '	;加空格保证两个字符串不在同一个段中
	db '3. search       '
	db '4 .view         '
	db '5. options      '
	db '6. help         '
datasg ends

codesg segment
	start:	mov ax,datasg
			mov ds,ax
			
			mov bx,0
			
			mov cx,6
		  s:mov al,[bx+3]
            and al,11011111B
            mov [bx+3],al
            add bx,16
            loops
            
            mov ax,4c00h
            int 21h
codesg ends
end start

The segment of each word in datasg uppercase letters, so we must use two heavy cycle, but should be used cx two cycles, it is necessary outer loop cx temporary value of the temporary register may be used, but generally to say, when needed temporary storage of data, we should use the stack

assume cs:codesg,ds:datasg,ss:stacksg

datasg segment
	db 'ibm             '
	db 'dec             '
	db 'dos             '
	db 'vax             '
datasg ends

stacksg segment
	dw 0,0,0,0,0,0,0,0	;定义一共栈段,容量为16个字节
stacksg ends

codesg segment
	start:	mov ax,stacksg
			mov ss,ax
			mov sp,16
			
			mov ax,datasg
			mov ds,ax
			
			mov bx,0
			
			mov cx,4
		 s0:push cx	;外层循环的cx压栈
		 	mov si,0
		 	
		 	mov cx,3
		  s:mov al,[bx+si]
            and al,11011111B
            mov [bx+si],al
            inc si
            loops
            
            add bx,16
            pop cx
            loop s0
            
            mov ax,4c00h
            int 21h
codesg ends
end start

Sixth experiment

Program, the first four letters of each word in datasg paragraph to uppercase letters

assume cs:codesg,ss:stacksg,ds:datasg

stacksg segment
	dw 0,0,0,0,0,0,0,0
stacksg ends

datasg segment
	db '1. display      '
	db '2. brows        '
	db '3. replace      '
	db '4. modify       '
datasg ends

codesg segment
	start:	mov ax,stacksg
    		mov ss,ax
    		mov sp,16
    		
    		mov ax,datasg
    		mov ds,ax
    		
    		mov bx,0
    		
    		mov cx,4
    	 s0:push cx
    	 	mov si,3
    	 	
    		mov cx,4
    	 s0:push cx
    	 	mov si,3
    	 	
    	 	mov cx,4
    	  s:mov al,[bx+si]
    	    and al,11011111B
    	    mov [bx+si],al
    	    inc si
    	    loop s
    	    
    	    pop cx
    	    add bx,16
    	    loop s0
    	    
    	    mov ax,4c00h
    	    int 21h
codesg ends
end start

Published 84 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43569916/article/details/104614846