我是靠谱客的博主 细腻乐曲,最近开发中收集的这篇文章主要介绍win32汇编以.386指令的MASM32题目做题记录 -- 循环结构,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

//最大公约

.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
InFmt BYTE '%d %d',0
OutFmt BYTE '%d',0AH,0
i DWORD 1
.data?
x DWORD ?
y DWORD ?
moded_1 DWORD ?
moded_2 DWORD ?
moded_ok DWORD ?
dived DWORD ?
temp DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR x,ADDR y
.while EAX != -1
MOV ECX,1
MOV EBX,y
.IF x < EBX
.while ECX <= x
MOV temp,ECX
MOV EAX,x
CDQ
IDIV ECX
MOV moded_1,EDX
MOV EAX,y
CDQ
IDIV ECX
MOV moded_2,EDX
.IF
moded_1 == 0 && moded_2 == 0
MOV moded_ok,ECX
MOV ECX,temp
.ENDIF
Inc ECX
.endw
.ELSE
.while ECX <= y
MOV temp,ECX
MOV EAX,x
CDQ
IDIV ECX
MOV moded_1,EDX
MOV EAX,y
CDQ
IDIV ECX
MOV moded_2,EDX
.IF
moded_1 == 0 && moded_2 == 0
MOV moded_ok,ECX
MOV ECX,temp
.ENDIF
Inc ECX
.endw
.ENDIF
invoke printf,ADDR OutFmt,moded_ok
invoke scanf,ADDR InFmt,ADDR x,ADDR y
.endw
invoke ExitProcess,0
end start
**

//最小公倍数

**
.386
.model flat, stdcall
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函数原型声明
option casemap :none
;*【*/
.data
InFmt BYTE '%d %d',0
OutFmt BYTE '%d',0AH,0
i DWORD 1
.data?
x DWORD ?
y DWORD ?
muled DWORD ?
moded_1 DWORD ?
moded_2 DWORD ?
moded_ok DWORD ?
dived DWORD ?
temp DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR x,ADDR y
.while EAX != -1
MOV EBX,y
.IF x > EBX
IMUL EBX,x
MOV muled,EBX
MOV ECX,muled
.while ECX >= x
MOV temp,ECX
MOV EAX,ECX
CDQ
IDIV x
MOV moded_1,EDX
MOV EAX,ECX
CDQ
IDIV y
MOV moded_2,EDX
.IF moded_1 == 0 && moded_2 == 0
MOV ECX,temp
MOV moded_ok,ECX
.ENDIF
SUB ECX,1
.endw
.ELSE
IMUL EBX,x
MOV muled,EBX
MOV ECX,muled
.while ECX >= y
MOV temp,ECX
MOV EAX,ECX
CDQ
IDIV x
MOV moded_1,EDX
MOV EAX,ECX
CDQ
IDIV y
MOV moded_2,EDX
.IF moded_1 == 0 && moded_2 == 0
MOV ECX,temp
MOV moded_ok,ECX
.ENDIF
SUB ECX,1
.endw
.ENDIF
invoke printf,ADDR OutFmt,moded_ok
invoke scanf,ADDR InFmt,ADDR x,ADDR y
.endw
invoke ExitProcess,0
end start

//字符串输出数字

.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
InFmt BYTE '%c',0
OutFmt BYTE '%c',0
.data?
c_ DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR c_
.while EAX == 1
.IF c_ >= '0' && c_ <= '9'
invoke printf,ADDR OutFmt,c_
.ENDIF
invoke scanf,ADDR InFmt,ADDR c_
.endw
invoke ExitProcess,0
end start

//统计正负数

.386
;选择的处理器
.model flat, stdcall
;存储模型,Win32程序只能用平展(flat)模型
option casemap:none
;指明标识符大小写敏感
includelib	msvcrt.lib	;引用C库文件
scanf PROTO C:DWORD,:vararg	;C语言scanf函数原型声明
printf PROTO C:DWORD,:vararg	;C语言printf函数原型声明
.data
;⑤数据段
szFmt
BYTE	'正数和为:%d 负数和为:%d',0
;*【*/
;TpFmt BYTE '%c',0
InFmt BYTE '%d',0
pn DWORD 0
nn DWORD 0
.data?
i SDWORD ?
;temp DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR i
.while EAX == 1
.IF i
> 0
MOV EBX,pn
ADD EBX,i
MOV pn,EBX
.ELSE
MOV EBX,nn
ADD EBX,i
MOV nn,EBX
.ENDIF
invoke scanf,ADDR InFmt,ADDR i
.IF EAX == -1
.BREAK
.ENDIF
.endw
invoke printf,ADDR szFmt,pn,nn
;*】*/
end start

//求模并相加

.386
.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib	msvcrt.lib
printf PROTO C:ptr sbyte,:vararg
scanf PROTO C:ptr sbyte,:vararg
.data
InFmt BYTE '%lf %lf',0
OutFmt BYTE '%.1lf',0
mo QWORD 0.0
.data?
a QWORD ?
b QWORD ?
a2f QWORD ?
b2f QWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR a,ADDR b
.while EAX != -1
FLD a
FMUL a
FSTP a2f
FLD b
FMUL b
FSTP b2f
FLD a2f
FADD b2f
FSQRT
FADD mo
FSTP mo
invoke scanf,ADDR InFmt,ADDR a,ADDR b
;.IF EAX == -1
.endw
invoke printf,ADDR OutFmt,mo
invoke ExitProcess,0
end start

//实数乘积和

.386
.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib	msvcrt.lib
printf PROTO C:ptr sbyte,:vararg
scanf PROTO C:ptr sbyte,:vararg
.data
InFmt BYTE '%lf %lf',0
OutFmt BYTE '%g',0
mo QWORD 0.0
.data?
a QWORD ?
b QWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR a,ADDR b
.while EAX != -1
FLD a
FMUL b
FADD mo
FSTP mo
invoke scanf,ADDR InFmt,ADDR a,ADDR b
;.IF EAX == -1
.endw
invoke printf,ADDR OutFmt,mo
invoke ExitProcess,0
end start

//实数和

.386
.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
includelib	msvcrt.lib
printf PROTO C:ptr sbyte,:vararg
scanf PROTO C:ptr sbyte,:vararg
option casemap :none
;*【*/
.data
InFmt BYTE '%lf',0
OutFmt BYTE '%g',0
mo QWORD 0.0
.data?
a QWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR a
.while EAX != -1
FLD a
FADD mo
FSTP mo
invoke scanf,ADDR InFmt,ADDR a
;.IF EAX == -1
.endw
invoke printf,ADDR OutFmt,mo
invoke ExitProcess,0
end start

//1+…+n

.386
.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
printf PROTO C:ptr sbyte,:vararg
scanf PROTO C:ptr sbyte,:vararg
.data
InFmt BYTE '%d',0
OutFmt BYTE '1+...+%d=%d',0
one DWORD 1
sum DWORD 0
.data?
n DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR n
MOV ECX,1
.while ECX <= n
MOV EAX,ECX
ADD EAX,sum
MOV sum,EAX
Inc ECX
.endw
invoke printf,ADDR OutFmt,n,sum
invoke ExitProcess,0
end start
**//1+2+3+4+...+100**
**//与上面不同,实现的是显示出中间加的数**
.386
.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
printf PROTO C:ptr sbyte,:vararg
scanf PROTO C:ptr sbyte,:vararg
.data
InFmt BYTE '%d',0
OutFmt BYTE '%d+',0
OutFmt2 BYTE '%d=%d',0
one DWORD 1
sum DWORD 0
.data?
n DWORD ?
temp DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR n
MOV ECX,1
.while ECX < n
MOV temp,ECX
MOV EAX,temp
ADD EAX,sum
MOV sum,EAX
invoke printf,ADDR OutFmt,ECX
MOV ECX,temp
Inc ECX
.endw
MOV EAX,sum
ADD EAX,n
MOV sum,EAX
invoke printf,ADDR OutFmt2,n,sum
invoke ExitProcess,0
end start

//奇数和

.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
InFmt BYTE '%d',0
OutFmt BYTE '1到%d的奇数和为%d',0
one DWORD 1
sum DWORD 0
two DWORD 2
.data?
n DWORD ?
.code
start:
invoke scanf,ADDR InFmt,ADDR n
MOV ECX,1
.while ECX <= n
MOV EAX,ECX
CDQ
IDIV two
.IF EDX != 0 ;奇数
MOV EAX,sum
ADD EAX,ECX
MOV sum,EAX
.ENDIF
Inc ECX
.endw
invoke printf,ADDR OutFmt,n,sum
invoke ExitProcess,0
end start

//阶乘

.386
.model flat, stdcall
option casemap:none
include	kernel32.inc
includelib	kernel32.lib
includelib	msvcrt.lib
printf PROTO C:DWORD,:vararg
;*【*/
scanf PROTO C:ptr sbyte,:vararg
.data
Fmt BYTE '%d',0
one DWORD 1
sum DWORD 1
.data?
n DWORD ?
.code
start:
invoke scanf,ADDR Fmt,ADDR n
MOV ECX,1
.while ECX <= n
MOV EAX,ECX
IMUL sum
MOV sum,EAX
Inc ECX
.endw
invoke printf,ADDR Fmt,sum
invoke ExitProcess,0
end start

最后

以上就是细腻乐曲为你收集整理的win32汇编以.386指令的MASM32题目做题记录 -- 循环结构的全部内容,希望文章能够帮你解决win32汇编以.386指令的MASM32题目做题记录 -- 循环结构所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部