汇编交换两个数的内容

来源:互联网 发布:v盾网络验证好破解吗 编辑:程序博客网 时间:2024/06/07 20:27
---------------------------------------;--交换两个数的内容;--汇编第二次作业;--时间:2015-04-08;--作者:计科三班2013301500100秦贤康;---------------------------------println  MACRO;输出回车换行    MOV  DL,0AH;输出换行    MOV  AH,02H;单字符显示    INT    21H    MOV  DL,0DH;输出回车    MOV  AH,02H    INT  21HENDMDATAS SEGMENT    num_a DW 4    num_b DW 6        ;提示字符串    px_s DB '*px = $'  py_s DB '*py = $'  x_s DB 'x = $'  y_s DB 'y = $'  a_s DB 'a = $'  b_s DB 'b = $'  change1 DB 'change1:$'  change2 DB 'change2:$'  DATAS ENDSSTACKS SEGMENT    STA DB 20 DUP(?);重复定义一个20BYTE的空间  TOP  EQU    LENGTH STA;TOP = STA的长度 STACKS ENDSCODES SEGMENT    ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART:;----------------主函数-----------------------    MOV AX,DATAS    MOV DS,AX             call exchange1 ;exchange(int ,int)   call print_a_b;显示num_a,num_b的结果printlncall exchange2;exchange(int *,int *)call print_a_b;显示num_a,num_b的结果    MOV AH,4CH    INT 21H;----------------主函数结束-----------------------;--输出main中num_a,num_b的值;--print_a_b proclea dx,a_s;输出 a = mov ah,09hint 21hmov dx,num_a;输出a的值    call disp_num;以10进制输出        mov dl,2ch;输出 ,    mov ah,02h    int 21h        lea dx,b_s;输出 b = mov ah,09hint 21h    mov dx,num_b;输出b的值    call disp_numprintln;回车换行retprint_a_b endp    ;--以10进制输出一个数字;--dx:要输出的数;--disp_num proc uses ax bx cx dxpush axpush bxpush cxpush dx    mov ax,dx    xor dx,dx        mov bx,10    mov cx,0dvd:    cmp ax,10    jb ed    div bx    add dl,30h    push dx    ;xor dx,dx    inc cx    jmp dvded:    add al,30h    push ax    inc cxo:    pop dx    mov ah,2    int 21h    loop o        pop ax    pop bx    pop cx    pop dx    retdisp_num endp;--交换两个数,直接传参数;--ax:数a;--bx:数b;--exchange1 proc uses bp di sipush bppush dipush simov bp,num_amov di,num_b;传参lea dx,change1mov ah,09hint 21hprintlnmov si,bpmov bp,dimov di,si     lea dx,x_s;输出 x = mov ah,09hint 21hmov dx,bp;输出x的值    call disp_num        mov dl,2ch;输出 ,    mov ah,02h    int 21h        lea dx,y_s;输出 y = mov ah,09hint 21h    mov dx,di;输出y的值    call disp_numprintln;回车换行    pop bp    pop si    pop di           retexchange1 endp;--交换两个数;--cx,dx为两个数的指针;--exchange2 proc uses si di cx bppush sipush dipush cxpush bplea si,num_alea di,num_b;传参lea dx,change2;输出提示mov ah,09hint 21hprintlnmov cx,[si];int temp = * pxmov bp,[di];*px = *pymov [si],bpmov [di],cx;*py = templea dx,px_s;输出 *px = mov ah,09hint 21hmov dx,[si];输出*px的值    call disp_num        mov dl,2ch;输出 ,    mov ah,02h    int 21h        lea dx,py_s;输出 *py = mov ah,09hint 21h    mov dx,[di];输出*py的值    call disp_numprintln;回车换行    pop si    pop di    pop cx        pop bp    retexchange2 endp    CODES ENDS    END START        

0 0
原创粉丝点击