汇编语言实验2

  1. 实验内容
    1) 有一字变量BUF1是以原码表示的有符号数,要求将其转换为反码和补码,分别存入BUF2和BUF3单元,并在屏幕上显示出来。
    2) 编写程序,将20个数据的数组分成两组,正数数组P和负数数组N,并分别显示两个数组的个数(P193 5.6)

  2. 源代码
    1)

1; multi-segment executable file template.

data segment
    ; add your data here!
    pkey db "press any key...$"
    BUF1 dw 1234H
    BUF2 dw ?
    BUF3 dw ?
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here        
    mov ax,BUF1    
    not ax
    mov BUF2,ax
    mov BUF3,ax
    add BUF3,1

    mov bx,BUF2
    mov ch,4
    call print1    

    call print2 ;回车换行

    mov bx,BUF3
    mov ch,4
    call print1

    mov ax, 4c00h ; exit to operating system.
    int 21h    
ends

print1 proc near
rotate:
    mov cl,4
    rol bx,cl
    mov al,bl
    and al,0FH
    add al,30H
    cmp al,3AH
    jl printit
    add al,7H   
printit:
    mov dl,al
    mov ah,2
    int 21H
    dec ch
    jnz rotate   
    ret
print1 endp

print2 proc near
    mov dl,0DH
    mov ah,2
    int 21H
    mov dl,0AH
    mov ah,2
    int 21H
    ret
print2 endp

end start ; set entry point and stop the assembler

2)

; multi-segment executable file template.

data segment
    ; add your data here!
    pkey db "press any key...$"
    M dw 9,8,7,6,5,4,3,2,1,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11
    P dw 20 dup(?)
    N dw 20 dup(?)
    A db 0;记录正数
    B db 0;记录负数
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here 
    lea bx,M
    mov si,0     
    mov cx,20

loop1:
    mov ax,[bx]+si
    add si,2
    cmp ax,0
    jg positive
    jmp negative

positive:    
    mov P+A,ax
    inc A
    jmp repeat

negative:
    mov N+B,ax    
    inc B

repeat:
    loop loop1

    mov bl,A
    mov ch,2
    call print1

    call print2

    mov bl,B
    mov ch,2
    call print1       

    mov ax, 4c00h ; exit to operating system.
    int 21h    
ends

print1 proc near
rotate:
    mov cl,4
    rol bl,cl
    mov al,bl
    and al,0FH
    add al,30H
    cmp al,3AH
    jl printit
    add al,7H   
printit:
    mov dl,al
    mov ah,2
    int 21H
    dec ch
    jnz rotate   
    ret
print1 endp

print2 proc near
    mov dl,0DH
    mov ah,2
    int 21H
    mov dl,0AH
    mov ah,2
    int 21H
    ret
print2 endp

end start ; set entry point and stop the assembler.

猜你喜欢

转载自blog.csdn.net/qq_41579622/article/details/81633556