1.输出hello,world!
assume cs:code,ds:data
data segment
string db 'Hello,World',0dh,0ah,'$'
data ends
code segment
start: mov ax,data
mov ds,ax
mov dx,offset string
mov ah,9
int 21h
mov ax,4c00h
int 21h
code ends
end start
编译:
链接:
题目:
如果x是正数,y = x,否则y = -x
assume cs:code,ds:data
data segment
x db -23
y db ?
data ends
code segment
start:
mov bx,data
mov ds,bx
mov al,x
cmp al,0
jg next
neg al
next: mov y,al
mov ax,4c00h
int 21h
code ends
end start
题目:
给定一个数值n,求sum = (n + 1) * n / 2
assume cs:code,ds:data
data segment
num dw 100 ;n的值
sum dd ?
data ends
code segment
start:
mov bx,data
mov ds,bx
mov ax,num
inc ax
mul num
shl dx,1
rcr ax,1
mov word ptr sum,ax
mov word ptr sum+2 ,dx
mov ax,4c00h
int 21h
code ends
end start
5050的十六进制为:13BA
题目:
判断两个数x,y,将两者中较大的数存入result
assume cs:code,ds:data
data segment
x dw 234
y dw 456
result dw ?
data ends
code segment
start:
mov bx,data
mov ds,bx
mov ax,x
mov bx,y
cmp ax,bx
jg l1
mov word ptr result,bx
jmp next
l1: mov word ptr result,ax
next: mov ax,4c00h
int 21h
code ends
end start
题目:
求1 ~ n的和,保存在sum,要求用循环
assume cs:code,ds:data
data segment
n dw 100
sum dw ?
data ends
code segment
start:
mov ax,data
mov ds,ax
mov cx,word ptr n
mov si ,0
mov ax,0
again: inc si
add ax,si
loop again
mov word ptr sum,ax
mov ax,4c00h
int 21h
code ends
end start
题目
分段函数,如果x < 1,y = x; 如果1<= x < 10,y = 2x - 1;如果x >= 10,y = 3x - 1
assume cs:code,ds:data
data segment
x dw 13
y dw ?
data ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,word ptr x
cmp ax,10
jge l1
cmp ax,1
jge l2
jmp l
l1: shl ax,1
add ax,word ptr x
jmp next
l2: shl ax,1
next: dec ax
l: mov word ptr y,ax
mov ax,4c00h
int 21h
code ends
end start
将ax的内容压入栈中,将栈中的内容弹出并输出。
assume cs:code,ds:data,ss:stack
stack segment
s db 1024 dup(?)
stack ends
data segment
n dw 10
data ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov ax,63h
push ax
pop dx
mov ah,02h
int 21h
mov ax,4c00h
int 21h
code ends
end start