王爽汇编语言实验9解答

实验9自己做下来感觉代码不难写,但是寄存器的分配很关键,要省着点用,另外用DEBUG调试非常费力,后来用了emu8086调试方便多了,可以单步调试成功就只是时间问题了。

assume cs:codesg 

;ds = char_array
;L[si] outsite loop
;l[di] insite  loop
;es:bx write memory

stack segment
	db 32 dup (0)  
stack ends

char_array segment
	db 'welcome to masm!'	;size = 16	index:[ds:di]
char_array ends

color_array segment
	db 00000010B,00100100B,01110001B ;-G,GR;WB  index:[ds:16+si]
color_array ends

addr_array segment
	dw 2000,2160,2320 ;  8c0,960,a00	index: [ds:32+si+si]
addr_array ends

codesg segment
start:
	;stack init
	mov ax,stack
	mov ss,ax
	mov sp,32		
	;ds init
	mov ax,char_array
	mov ds,ax
	;L_index init		
	mov si, 0		
	;L times init	
	mov cx,3

LOOP_OUT:
	;save LOOP_OUT registers
	push cx
	;l_index init
	mov di,0	
	;get addr offset into bx
	mov ax,si
	add ax,ax
	add ax,20h
	mov bx,ax
	mov bx,[bx]
	;get the char color into al
	mov al,[10h+si]
	;write char
	mov dx,0b800h
	mov es,dx	
	;l times init
	mov cx,16
	
LOOP_IN:
	;get the char[si] into ah
	mov ah,[di]	
	mov es:[bx],ah
	mov es:[bx+1],al
	;update l_index
	inc di
	inc bx
	inc bx	
	loop LOOP_IN	
		
	pop cx
	;update L_index
	inc si
	loop LOOP_OUT
	
	mov ax,4c00H 
	int 21H	

codesg ends

end start
	
	
	
	
	
	
	
	
	
	
	
	

 

你可能感兴趣的:(X86汇编语言)