王爽彙編語言實驗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
	
	
	
	
	
	
	
	
	
	
	
	

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章