水铝英石

微机原理实验

实验一 (忘了)

DATAS SEGMENT
    BUF DB 23H,16H,09H,20H,64H,8AH,91H,35H,2BH,7FH
    CN EQU $-BUF;
DATAS ENDS

STACKS SEGMENT STACK 'STACK'
    DB  256 DUP(0)
    TOP EQU $-STA; 
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START: PUSH DS;
    XOR AX,AX;
    PUSH AX;
    
    MOV AX,DATAS
    MOV DS,AX

    MOV BX,OFFSET BUF;
    MOV CX,CN;
    DEC CX;
    MOV AL,[BX];
    INC BX;
LP: CMP AL,[BX];
    JBE NEXT;
    MOV AL,[BX];
NEXT: INC BX;
    DEC CX;
    JNZ LP;
    ;CALL DISP_AL;
    MOV AH,4CH
    INT 21H
CODES ENDS
    END START

实验2

;计算
DATA   SEGMENT
    W   DW  -340
    X   DW  1000 
    Y   DW  -12
    Z   DW  20
    RESULT DW 2 DUP(?)   
    RESULT2 DW 2 DUP(?)
DATA ENDS
CODE SEGMENT
     ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
      MOV DS,AX
      MOV AX,X
      IMUL Y
      MOV CX,AX
      MOV BX,DX
      MOV AX,Z
      CWD
      ADD CX,AX
      ADC BX,DX
      SUB CX,220
      SBB BX,0
      MOV AX,W
      CWD
      SUB AX,CX
      SBB DX,BX
      IDIV X
      MOV RESULT,AX       
      MOV RESULT2,DX
      ;MOV RESULT+2,DX
      MOV AH,4CH
      INT 21H
CODE      ENDS
      END START

实验3

;用比较 比较大小
DATA SEGMENT USE16
    X DB 19
    Y DB -25
    Z DB 38
    MAX DB ?    
DATA ENDS
;description
CODE SEGMENT USE16
    ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
    MOV DS,AX

    MOV AL,X
    CMP AL,Y
    JG TEMP1
    MOV AL,Y
TEMP1: CMP AL,Z
    JG TEMP2
    MOV AL,Z
TEMP2: MOV MAX,AL

    MOV AH,4CH
    INT 21H
CODE ENDS
    END START

实验4

; copy字符串
DATA SEGMENT
    STR1 DB '0123456789ABCDEFGHIJ'
    CN EQU $-STR1
    STR2 DB CN DUP(?)    ;将 ? 改成 0 在8086asm能用,dosbox随意
DATA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA,ES:DATA
START:  MOV AX,DATA
        MOV DS,AX
        MOV ES,AX
            
    MOV CX,CN
    LEA SI,STR1
    LEA DI,STR2
    CLD 
    REP MOVSB

    MOV AH,4CH
    INT 21H
CODE ENDS
    END START
                                       ;查看0的个数(这个0是字符0,是30H)
DATA SEGMENT
    array DB '10120003456789ABCDEFGHIJ'
    CN EQU $-array
    mask db cn dup('0')
    num db 0
DATA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA,ES:DATA
START:  MOV AX,DATA
        MOV DS,AX
        MOV ES,AX
    xor ax,ax
    MOV CX,CN
    LEA SI,array
    LEA DI,mask
    CLD 
recmp:
    REPNE CMPSB
    inc num
    cmp cx,0
    je exit
    jmp recmp
exit:
    DEC num         ;由于最后CMPSB结束后还会num+1所以这里需要减一
    MOV AH,4CH
    INT 21H
CODE ENDS
    END START
;排序,冒泡
DATA SEGMENT
    A DB 23,-15,34,67,-19,0,-12,89,120,55
    CN EQU $-A
DATA ENDS
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA,ES:DATA
START:  MOV AX,DATA
        MOV DS,AX
       
    MOV CX,CN-1
LP1:MOV SI,0
    PUSH CX
    MOV DL,1
LP2:MOV AL,A[SI]
    CMP AL,A[SI+1]
    JNL NEXT   ;假如 n 不小于(大于) n+1,交换
    XCHG AL,A[SI+1]
    MOV A[SI],AL
    MOV DL,0
NEXT:INC SI
    LOOP LP2
    POP CX
    DEC CX
    CMP DL,0
    JZ LP1

    MOV AH,4CH
    INT 21H
CODE ENDS
    END START
;description
 搞到一半的大问题
DATA SEGMENT
    array DB 23,-15,34,67,-19,0,-12,89,120,55
    length EQU $-array
    pleft DB ?   ;left pointer 
    pright DB ?  ;right pointer
    temp DB ?    ;inter pointer message
    flag DB ?    ;choose left or right
DATA ENDS
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA,ES:DATA
START:  MOV AX,DATA
        MOV DS,AX
        MOV DS,AX
    mov si,OFFSET array
    mov cx,length
    call sort
    MOV AH,4CH
    INT 21H
sort PROC NEAR
    PUSHA  ;不知道能不能用系列(80286扩充
    push pleft
    push pright
    push temp
    push flag
    
    cmp cx,02h
    jl  exit 
ini:mov al,array[si] ;本来想给temp但不必
    mov pleft,0
    mov pright,cx
    dec pright
    mov flag,1
    mov cx,ffh
    
lp1:cmp flag,1
    jz moveright
    cmp flag,0
    jz moveleft
    cmp pleft,pright
    jge lp1
    jmp waittoexit
    
    
moveright:
    mov si,pright
    cmp array[si],al
        jge dealright
    mov dl,array[si];dl代表array right
    mov si,pleft
    mov array[si],dl
    inc pleft
    jmp lp1
dealright:
    dec pright
    jmp lp1
    
moveleft:
    mov si,pleft
    cmp array[si],al
        jge dealleft
    mov dl,array[si];dl代表array left
    mov si,pright
    mov array[si],dl
    inc pright
    jmp lp1
dealleft:
    dec pright
    jmp lp1

waittoexit: 
    mov si,ileft
    mov array[si],al
recursion:
    mov si,OFFSET array ; recursion
    mov cx,pleft
    call sort    ;sort(array,pleft)
    mov si,OFFSET array
    add si,pleft
    inc si          
    mov cx,length
    sub cx,pleft
    dec cx
    call sort   ;sort(array+left+1,length-pleft-1)
exit: pop flag
    pop temp
    pop pright
    pop pleft
    POPA   ;不知道能不能用,先用着
    RET
sort ENDP

CODE ENDS
    END START

实验5

;反向输出字符串
data SEGMENT USE16
    string db 'hello world!','$'
data ENDS
;description
stack SEGMENT USE16
    dw 100 dup(0)
stack ENDS
;description
code SEGMENT USE16
    assume cs:code,ds:data,ss:stack
start:  MOV AX,data
        MOV DS,AX
    lea bx,string
    push bx
    call display
    pop bx
    mov dl,[bx]
    mov ah,2
    int 21h
    mov ah,4ch
    int 21h
;description
display PROC
    push AX
    push bx
    push dx
    push bp

    mov bp,sp
    mov bx,[bp+10]
    mov al,byte ptr[bx]
    cmp al,'$'
    jnz re_call
    jmp return
re_call:
    inc bx
    push bx
    call display
    pop bx
    mov dl,[bx]
    mov ah,2
    int 21h
return: 
    pop bp
    pop dx
    pop bx
    pop AX
    ret
display ENDP
    
code ENDS
    end start

发表评论

邮箱地址不会被公开。 必填项已用*标注

滚动到顶部