汇编十道小题

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

8、从包含10个无符号数的字节数组array中选出最小的一个数存于变量MIN中,并将该数以十进制形式显示出来。

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

猜你喜欢

转载自www.cnblogs.com/lihello/p/11520790.html