彙編十道小題

目錄

 

1、從鍵盤輸入一個字符串(長度不超過30),統計字符串中非數字的個數,並將統計的結果顯示在屏幕上,用EXE格式實現。

2、統計一個16位二進制數中1的個數,並將結果以十六進制形式顯示在屏幕上,用COM格式實現。

3、從鍵盤輸入兩個一位十進制數,求它們的和,並將結果以十進制形式輸出。

4、從鍵盤輸入一個十進制個位數,在屏幕上顯示相應數量的該數。例如,輸入3,屏幕上將顯示“333”。

5、求100以內所有奇數的和,存於字變量X中。

6、將BX中的數以二進制形式在屏幕上顯示出來。

7、字節數組X中存放着 0~F共16個十六進制數,請將這些數以十六進制形式顯示在屏 幕上。

9、設在起始地址爲STRING的存儲空間存放了一個字符串(該串已存放在內存中,無需輸入,且串長不超過99),統計字符串中字符“A”的個數,並將結果顯示在屏幕上。

10、比較兩個等長的字符串,若相同,則輸出Match!,若不同,則輸出No Match!。


 

1、從鍵盤輸入一個字符串(長度不超過30),統計字符串中非數字的個數,並將統計的結果顯示在屏幕上,用EXE格式實現。

data segment
  str db 30,?,30 dup(?);30是限制個數,?存儲實際個數
  count db 0
data ends
code segment
  assume cs:code,ds:data
  main proc far
start:
    push ds
    mov ax,0
    push ax

    mov ax,data
    mov ds,ax
    
    lea dx,str
    mov ah,0ah
    int 21h
    
    mov cl,str+1
    
    mov ch,0
    mov si,2
  L3:
    cmp str[si],30h
    jae L1
    inc count
    jmp L2
  L1:
    cmp str[si],39h
    jbe L2
    inc count
  L2:
    inc si
    loop L3

    mov ah,02h
    mov dl,0dh
    int 21H 
    mov ah,02h
    mov dl,0ah
    int 21H 

    lea bx,count
    mov ax,[bx]
或
mov al,count
mov ah,00h
    mov bl,10
    div bl;餘數在ah,商在al
    mov dx,ax
    add dx,3030h;轉化成十\個位對應的ASCII碼
    mov ah,2
    int 21h
    mov dl,dh
    mov ah,2
    int 21h 

    mov ah,4ch
    int 21h

code ends
end start

2、統計一個16位二進制數中1的個數,並將結果以十六進制形式顯示在屏幕上,用COM格式實現。

  code segment
  org 100h
  assume cs:code
  main proc near
  start:
	mov bx,0a39h
	mov si,0
	mov cx,16
  next:
	shr bx,1
	jnc l1
	inc si
  l1:
	loop next
	mov dx,si
	add dx,30h
	cmp dl,3ah ;看1是否超過十個
	jb l2
	add dl,7
  l2:	
	mov ah,02h
	int 21h
	mov ax,4c00h
	int 21h
	main endp
code ends
end start

3、從鍵盤輸入兩個一位十進制數,求它們的和,將結果以十進制形式輸出

code segment
  assume cs:code
start:

  mov ah,01
  int 21h
  mov bl,al;存儲在al中
  mov ah,01
  int 21h
  mov bh,al
  sub bx,3030h
  add bl,bh
  
  mov al,bl
  mov ah,00h
  mov bl,10
  div bl
  
  add ax,3030h
  push ax;保護ax中數據
  
  mov dl,al
  mov ah,2
  int 21h
  
  pop ax

  mov dl,ah
  mov ah,2
  int 21h
  
  mov ah,4ch
  int 21h

code ends
end start

4、從鍵盤輸入一個十進制個位數,在屏幕上顯示相應數量的該數。例如,輸入3,屏幕上將顯示“333”。

code segment
assume cs:code
start:
  mov ah,01h
  int 21h
  
  mov bl,al
  
  sub al,30h
  mov cl,al
  mov ch,00h
  
  mov ah,02h
  mov dl,0dh
  int 21h
  
  mov ah,02h
  mov dl,0ah
  int 21h
  
L1:
  mov dl,bl
  mov ah,02h
  int 21h
  loop L1
  
  mov ah,4ch
  int 21h
 
code ends
end start

5、求100以內所有奇數的和,存於字變量X中。

data segment
  x dw ?
data ends
code segment
  assume cs:code,ds:data
  main proc far
start:
    mov ax,data
    mov ds,ax
    	mov ax,0
   	 	mov bx,1
    	mov cx,50
 	L1:	add ax,bx
    	add bx,2
    	loop L1
mov x,ax
mov ah,04h
int 21h
    	main endp
code ends
end start

6、將BX中的數以二進制形式在屏幕上顯示出來。

code segment
  assume cs:code
  start:
  	mov bx,1234h
  	mov cx,16
  l1:
  	mov dl,30h
  	shl bx,1
  	jnc l2
  	inc dl
  l2:
  	mov ah,02h
  	int 21h
  	loop l1
  	
  	mov ah,4ch
  	int 21h
code ends
end start

7、字節數組X中存放着 0~F共16個十六進制數,請將這些數以十六進制形式顯示在屏 幕上。

data segment
  x db 0,1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh
data ends

code segment
  assume cs:code,ds:data
  start:
  	mov ax,data
  	mov ds,ax
  	
  	mov cx,16
  	mov si,0
  	
  l1:
  	mov dl,x[si]
  	add dl,30h
  	
  	cmp dl,39h
  	jbe l2
  	add dl,7
  l2:
  	mov ah,02h
  	int 21h
  	
  	inc si
  	loop l1
  	
  	mov ah,4ch
  	int 21h
code ends
end start
data segment 
  array db 33,57,65,62,90,69,85,56,53,39
  min db ?
data ends
stack segment
  dw 10 dup(?)
stack ends
code segment 
  assume cs:code,ds:data,ss:stack
  start:
  	mov ax,data
  	mov ds,ax
  	
  	mov al,255
  	mov cx,10
  	mov si,0
  	mov di,0
  l1:
  	cmp al,array[si]
  	jbe l2
  	mov al,array[si]
  l2:
  	inc si
  	loop l1
  	
  	mov min,al
  	mov ah,0

  l3:
  	mov bl,10
  	div bl
  	mov dl,ah
  	push dx
  	inc di
  	mov ah,0
  	cmp ax,0
  	jz l4
  	loop l3
  l4:
  	mov cx,di
  
  l5:
  	pop dx
  	add dl,30h
  	
  	mov ah,02h
  	int 21h
  	loop l5
  	
  	mov ah,4ch
  	int 21h
  	
code ends
end start

9、設在起始地址爲STRING的存儲空間存放了一個字符串(該串已存放在內存中,無需輸入,且串長不超過99),統計字符串中字符“A”的個數,並將結果顯示在屏幕上。

data segment 
  string db 'aaaaaaaaaasbbbbbcccy'
  len dw $-string
  result db 0
data ends
code segment
  assume cs:code,ds:data
  
  start:
  	mov ax,data
  	mov ds,ax
  	mov di,0
  	mov cx,len
  	lea si,string
  	
  l1:
  	lodsb
  	cmp al,'a'
  	jnz l2
  	inc result;直接加即可
  l2:
  	loop l1
  	
  	mov al,result;直接將result傳遞給al
  	mov ah,00h
  l3:
  	mov bl,10
  	div bl
  	mov dl,ah
  	push dx
  	inc di
  	mov ah,0
  	cmp ax,0
  	jz l4
  	loop l3
  l4:
  	mov cx,di
  l5:
  	pop dx
  	add dl,30h
  	mov ah,02h
  	int 21h
  	loop l5
  	
  	mov ah,4ch
  	int 21h
code ends
end start 	

10、比較兩個等長的字符串,若相同,則輸出Match!,若不同,則輸出No Match!。

data segment
  str1 db 'computer'
  len1 dw $-str1
  str2 db 'computer'
  mess1 db 'MATCH$'
  mess2 db 'NO MATCH$'
data ends

code segment
  assume cs:code,ds:data
  start:
  	mov ax,data
  	mov ds,ax
  	mov es,ax
  	lea si,str1
  	lea di,str2
  	cld
  	mov cx,len1	
  	repe cmpsb
  	jz l1
  	lea dx,mess2
  	jmp l2
  l1:
  	lea dx,mess1
  l2:
  	mov ah,09h
  	int 21h
  	
  	mov ah,4ch
  	int 21h
  	
code ends
end start

 

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