仅供学习参考,自己做出来的才是王道。
1.键盘输入一个字母,然后输出该字母。
Use the keyboard to input a letter, and then output the letter.
运行后若输入Run the program and input:A B
则结果输出Output the result:'A’ “B”
运行后若输入Run the program and input:a b
则结果输出Output the result:'a’ “b”
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be included
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
;*【*/
fmt byte '%c %c' ,0
a byte ?
b byte ?
fmt1 byte '"%c"',0
fmt2 byte "'%c' ",0
.code
start:
invoke scanf, addr fmt,addr a,addr b
invoke printf, addr fmt2,dword ptr a
invoke printf, addr fmt1,dword ptr b
;*】*/
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
2.键盘输入2个整数,然后按相反顺序输出这2个整数。
Use the keyboard to input 2 integers, and then output these 2 integers in reverse order.
运行后若输入Run the program and input:3 4
则结果输出Output the result:4 3
运行后若输入Run the program and input:1 2
则结果输出Output the result:2 1
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be included
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
;*【*/
fmt byte '%d %d',0
a dword ?
b dword ?
.code
start:
invoke scanf, addr fmt, addr a, addr b
invoke printf, addr fmt, b,a
;*】*/
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
3.键盘输入2个实数,然后按相反顺序输出这2个实数。
Input 2 real numbers from the keyboard, and then output these 2 real numbers in reverse order.
运行后若输入Run the program and input:3.3 4.45
则结果输出Output the result:4.45 3.3
运行后若输入Run the program and input:1.35 2.4
则结果输出Output the result:2.4 1.35
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be included
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
;*【*/
fmt byte '%lf %lf',0
a qword ?
b qword ?
fmt1 byte '%g %g',0
.code
start:
invoke scanf, addr fmt, addr a, addr b
invoke printf, addr fmt1, b,a
;*】*/
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
4.定义结构体商品,含编号、品名、单价、数量,输入一个商品信息求其金额并输出(按“%g”格式输出)。
Define a product structure, including serial number, product name, unit price, and quantity. Enter a product information to find the amount and output (output in “%g” format).
若运行后输入Run the program and input:S001 小刀 4.5 2
则运行结果输出Output the result:编号:S001,品名:小刀,单价:4.5,数量:2,金额:9
.386
.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTO C:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTO C:ptr sbyte,:vararg ;C语言scanf函数原型声明
;*【*/
.data
fmt DB '%s %s %lf %d',0
fmt1 DB '编号:%s,品名:%s,单价:%g,数量:%d,金额:%g',0
Goods struct
no byte 14 DUP(?)
gname byte 20 DUP(?)
cost qword ?
num dword ?
total qword ?
Goods ends
s Goods <>
.code
start:
invoke scanf,addr fmt,addr s.no,addr s.gname ,addr s.cost,addr s.num
FLD s.cost
Fimul s.num
FSTP s.total
invoke printf,addr fmt1, addr s.no,addr s.gname ,s.cost,s.num,s.total
invoke ExitProcess,0
end start
;*】*/
1.键盘输入整数x、y、z的值,求如下表达式的值:
Enter the values of integers x, y, and z from the keyboard, and obtain the value of the following expression:
x*y+x%y-z
运行后若输入Run the program and input:8 4 2
则结果输出Output the result:8*4+8%4-2=30
;*【*/
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be inc luded
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
fmt DB '%d %d %d',0
x dword ?
y dword ?
z dword ?
a dword ?
b dword ?
d dword ?
e dword ?
fmt1 DB '%d*%d+%d%%%d-%d=%d',0
.code
start:
invoke scanf, addr fmt, addr x, addr y, addr z
MOV EAX,x
IMUL y
MOV a,EAX
MOV EAX,x
CDQ
IDIV y
MOV b,EDX
MOV EAX,a
ADD EAX,b
MOV d,EAX
MOV EAX,d
SUB EAX,z
MOV e,EAX
invoke printf, addr fmt1,x,y,x,y,z,e
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
;*】*/
2.键盘输入整数x、y、z的值,求如下表达式的值:
Enter the values of integers x, y, and z from the keyboard, and obtain the value of the following expression:
x*y+x/y-z
运行后若输入Run the program and input:8 4 2
则结果输出Output the result:8*4+8/4-2=32
;*【*/
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be inc luded
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
fmt DB '%d %d %d',0
x dword ?
y dword ?
z dword ?
a dword ?
b dword ?
d dword ?
e dword ?
fmt1 DB '%d*%d+%d/%d-%d=%d',0
.code
start:
invoke scanf, addr fmt, addr x, addr y, addr z
MOV EAX,x
IMUL y
MOV a,EAX
MOV EAX,x
CDQ
IDIV y
MOV b,EAX
MOV EAX,a
ADD EAX,b
MOV d,EAX
MOV EAX,d
SUB EAX,z
MOV e,EAX
invoke printf, addr fmt1,x,y,x,y,z,e
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
;*】*/
3.输入两个小写字母,然后输出其相应的大写字母。
Enter two lowercase letters, and then output their corresponding uppercase letters.
运行后输入Run the program and input:
a b
则结果输出Output the result:
A B
.386 ;选择的处理器
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件
includelib kernel32.lib ;要引用的库文件
includelib msvcrt.lib ;引用C库文件
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明
.data ;⑤数据段
;*【*/
fmt byte '%c %c',0
a byte ?
b byte ?
.code
start:
invoke scanf, addr fmt, addr a, addr b
sub a,32
sub b,32
invoke printf, addr fmt, dword ptr a, dword ptr b
;*】*/
invoke ExitProcess,0 ;退出进程,返回值为0
end start
/***asm***/
1.键盘输入实数x、y、z的值,求如下表达式的值(数值结果用%g格式输出):
Enter the values of real numbers x, y, and z from the keyboard, and obtain the value of the following expression (the numerical result is output in %g format):
x*y+x/y-z
运行后若输入Run the program and input:7.0 4.0 2.0
则结果输出Output the result:7×4+7/4-2=27.75
(编辑格式限制:实际“×”要用星号)
;*【*/
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be inc luded
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
fmt byte '%lf %lf %lf',0
x qword ?
y qword ?
z qword ?
a qword ?
b qword ?
d qword ?
e qword ?
fmt1 byte '%g*%g+%g/%g-%g=%g',0
.code
start:
invoke scanf, addr fmt, addr x, addr y,addr z
FLD x
FMUL y
FSTP a
FLD x
FDIV y
FSTP b
FLD a
FADD b
FSTP d
FLD d
FSUB z
FSTP e
invoke printf, addr fmt1,x,y,x,y,z,e
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
;*】*/
1.键盘输入实数x的值,求如下表达式的值(保留2位小数):
Enter the value of the real number x from the keyboard, and obtain the value of the following expression (retaining 2 decimal places):
运行后若输入Run the program and input:0.5
则结果输出Output the result:0.65
;*【*/
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be inc luded
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
fmt byte '%lf',0
x qword ?
y qword ?
z qword ?
a qword 2.0
b qword ?
d qword ?
e qword ?
f qword ?
fmt1 byte '%.2lf',0
.code
start:
invoke scanf, addr fmt, addr x
FLD x
FMUL x
FSTP y
FLD x
Fsin
FSTP z
FLD x
Fcos
FSTP b
FLD a
FADD b
FSTP d
FLD z
FDIV d
FADD y
FSTP e
FLD e
Fsqrt
FSTP f
invoke printf, addr fmt1,f
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
;*】*/
2.已知机器人当前的位置为(0,0),若该机器人的下一个位置为(x,y),请计算该机器人前进的方向角(角度)。输入x和y值,用反正切函数指令(FPATAN)求角度。
It is known that the current position of the robot is (0,0). If the next position of the robot is (x,y), please calculate the direction angle (angle) of the robot. Enter the x and y values, and use the arctangent function command (FPATAN) to obtain the angle.
运行后若输入Run the program and input:1.0 1.0
则结果输出Output the result:45
运行后若输入Run the program and input:-1.0 1.0
则结果输出Output the result:135
运行后若输入Run the program and input:1.0 -1.0
则结果输出Output the result:-45
运行后若输入Run the program and input:-1.0 -1.0
则结果输出Output the result:-135
;*【*/
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be inc luded
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
fmt byte '%lf %lf',0
x qword ?
y qword ?
z qword ?
a qword 180.0
b qword 3.1415926
d qword ?
fmt1 byte '%g',0
.code
start:
invoke scanf, addr fmt, addr x,addr y
FLD y
FLD x
Fpatan
FSTP z
FLD z
FMUL a
FDIV b
FSTP d
invoke printf, addr fmt1,d
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
;*】*/
3.键盘输入实数y和实数x的值,求q=ylg(x)的值(用%g格式显示):
Input the value of real number y and real number x with the keyboard, and find the value of q=ylg(x) (displayed in %g format):
运行后若输入Run the program and input:0.5 10
则结果输出Output the result:0.5
运行后若输入Run the program and input:1.5 0.1
则结果输出Output the result:-1.5
;*【*/
.386 ;选择的处理器Choose the processor
.model flat, stdcall
option casemap:none ;指明标识符大小写敏感
include kernel32.inc ;要引用的头文件Specify the header file to be inc luded
includelib kernel32.lib ;要引用的库文件Specify the library file to be included
includelib msvcrt.lib ;引用C库文件Specify the C library file to be included
scanf PROTO C:DWORD,:vararg ;C语言scanf函数原型声明 Declare the C scanf function prototype
printf PROTO C:DWORD,:vararg;C语言printf函数原型声明 Declare the C printf function prototype
.data ;⑤数据段 data segment
fmt byte '%lf %lf',0
x qword ?
y qword ?
a qword ?
b qword 10.0
d qword ?
q qword ?
fmt1 byte '%g',0
.code
start:
invoke scanf, addr fmt, addr y,addr x
fld y
fld x
fyl2x
Fdiv y
fstp a
fld y
fld b
fyl2x
Fdiv y
fstp d
FLD a
Fdiv d
Fmul y
Fstp q
invoke printf, addr fmt1,q
invoke ExitProcess,0 ;退出进程,返回值为0 Exit process, return 0
end start
;*】*/
4.键盘输入实数q,求实数q的整数部分n和小数部分p并输出(用%g格式输出):
Input the real number q from the keyboard, obtain the integer part n and the decimal part p of the real number q and output (output in %g format):
运行后若输入Run the program and input:4.0
则结果输出Output the result:4 0
运行后若输入Run the program and input:4.1
则结果输出Output the result:4 0.1
运行后若输入Run the program and input:4.9
则结果输出Output the result:4 0.9
运行后若输入Run the program and input:-4.0
则结果输出Output the result:-4 -0
运行后若输入Run the program and input:-4.1
则结果输出Output the result:-4 -0.1
运行后若输入Run the program and input:-4.9
则结果输出Output the result:-4 -0.9
;*【*/
.386
.model flat, stdcall
option casemap:none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
scanf PROTO C:DWORD,:vararg
printf PROTO C:DWORD,:vararg
.data
fmt byte '%lf',0
q qword ?
n qword ?
p qword ?
a qword 1.0
fmt1 byte '%g %g',0
.code
start:
invoke scanf, addr fmt, addr q
FLD a
FLD q
Fprem
FSTP p
FSTP a
FLD q
Fsub p
FSTP n
invoke printf, addr fmt1,n,p
invoke ExitProcess,0
end start
;*】*/
5.键盘输入实数p(p介于-1~1之间)的值,求v=2^p的值(保留3位小数):
Use the keyboard to input the value of the real number p (p is between -1 and 1), and obtain the value of v=2p (retain 3 decimal places):
运行后若输入Run the program and input:0.5
则结果输出Output the result:1.414
运行后若输入Run the program and input:1
则结果输出Output the result:2.000
运行后若输入Run the program and input:-1
则结果输出Output the result:0.500
;*【*/
.386
.model flat, stdcall
option casemap:none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
scanf PROTO C:DWORD,:vararg
printf PROTO C:DWORD,:vararg
.data
fmt byte '%lf',0
v qword ?
p qword ?
q qword ?
a qword 1.0
fmt1 byte '%.3lf',0
.code
start:
invoke scanf, addr fmt, addr p
FLD p
F2xm1
Fadd a
FSTP v
invoke printf, addr fmt1,v
invoke ExitProcess,0
end start
;*】*/
6.键盘输入实数v和整数n的值,求w=v×(2^n)的值:
Enter the value of the real number v and the integer n with the keyboard, and obtain the value of w=v*2n:
运行后若输入Run the program and input:1.5 3
则结果输出Output the result:1.5×2^3=12
;*【*/
.386
.model flat, stdcall
option casemap:none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
scanf PROTO C:DWORD,:vararg
printf PROTO C:DWORD,:vararg
.data
fmt byte '%lf %lf',0
v qword ?
n qword ?
w qword ?
fmt1 byte '%g*2^%g=%g',0
.code
start:
invoke scanf, addr fmt, addr v,addr n
FL