一个简单的汇编程序

今天,第一次打汇编代码,编译,连接,用debug调试了一下。

win10 搭建汇编环境。百度或者参考https://blog.****.net/hjw1542254356/article/details/79721546

assume cs:codesg //assume
codesg segment
    mov ax, 0123h//让ax位123(十六进制)
    mov bx, 0456h
    add ax,bx//ax=ax+bx
    add ax,ax

    mov ax, 4c00h//暂时不知道这两行有什么用 但是需要写上
    int 21h
codesg ends
end

一个简单的汇编程序

 

接着做了一道简单的题目,利用栈将ax和bx的交换,后进先出。

题目:将10000H~1000F这段看见当做栈,初始状态栈是空的。设置ax=001AH,bx=00ABH,利用栈,交换AX,BX中的数据

代码如下:

assume cs:codesg
codesg segment
    mov ax,1000h
    mov ss,ax//注意sp,因为执行入栈函数push时,栈顶指针要先移动也就是sp=sp-2所以
    mov sp,0010h// 初始状态 sp应该为000F+2即0010h
    mov ax,001ah
    mov bx,001bh
    push ax
    push bx
    pop ax
    pop bx
    mov ax,4c00h
    int 21h
codesg ends
end