当前位置: 首页 > news >正文

Intel汇编语言程序设计(第7版)第四章编程练习题答案

1. 大端序转成小端序

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib.stack 4096.data 
bigEndian BYTE 12h, 34h, 56h, 78h
littleEndian DWORD ?Fmt BYTE "0x%08X", 0
Caption BYTE "Caption", 0
Buf BYTE 64 DUP(0)
.code start:mov eax, DWORD PTR [bigEndian]mov littleEndian, eaxinvoke wsprintf, OFFSET Buf, OFFSET Fmt, [littleEndian] invoke MessageBox, NULL, OFFSET Buf,  OFFSET Caption, MB_OKinvoke ExitProcess, 0ret
end start

2. 交换数组元素对

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.lib.stack 4096.data 
Array 		BYTE 		11h, 22h, 33h, 44h, 55h, 66h, 77h, 88h
ArrayLen 		DWORD 		($ - Array) / SIZEOF WORD
TmpBuf		BYTE			0Pause BYTE "pause", 0
Fmt BYTE "0x%02X ", 0
Buf BYTE 64 DUP(0)
.code start:mov ecx, ArrayLenxor ebx, ebx 
Exchange:mov al, [Array + ebx]mov TmpBuf, al				; 保存第1个数inc ebx mov al, [Array + ebx]		; 保存第2个数dec ebxmov [Array + ebx], al		; 赋值第1个数inc ebx mov al, TmpBuf		mov [Array + ebx], al		; 赋值第2个数inc ebxloop Exchangexor ebx, ebx
Print:mov al, [Array + ebx]invoke crt_printf, OFFSET Fmt, al inc ebxcmp ebx, LENGTHOF Arrayjz Endingjmp PrintEnding:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

3. 数组元素间隔之和

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.lib.stack 4096.data 
Array 		DWORD 		0, 2, 5, 9, 10
ArrayLen 		DWORD 		($ - Array) / SIZEOF DWORD
TmpBuf		DWORD			0Pause BYTE "pause", 0
Fmt BYTE "%d", 0
Buf BYTE 64 DUP(0)
.code start:mov ecx, ArrayLenxor edx, edxmov ebx, TYPE Array
SUMTWO:mov eax, [Array + ebx]mov TmpBuf, eaxsub ebx, TYPE Arraymov eax, [Array + ebx]sub TmpBuf, eaxadd edx, TmpBufadd ebx, TYPE Arrayloop SUMTWOinvoke crt_printf, OFFSET Fmt, edx
Ending:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

4. 将字数组复制到双字数组

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.lib.stack 4096.data 
wArray 		WORD		5, 9, 12, 31, 46, 68
ArrayLen 		DWORD 		($ - wArray) / SIZEOF WORD
dwArray		DWORD		32 DUP(0)
TmpBuf		DWORD			0Pause BYTE "pause", 0
Fmt BYTE "%d ", 0
Buf BYTE 64 DUP(0)
.code start:mov ecx, ArrayLenxor eax, eaxxor esi, esi
L0:movzx eax, WORD PTR [wArray + esi * TYPE wArray]mov [dwArray + esi * TYPE dwArray], eax  inc esiloop L0xor edi, edi
L1:invoke crt_printf, OFFSET Fmt, DWORD PTR [dwArray + edi * TYPE dwArray]inc edicmp edi, ArrayLenjz Endingjmp L1Ending:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

5. 斐波那契数列

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.libFIBNUM = 7.stack 4096.data 
Fib0		DWORD 0
Fib1		DWORD 1
dwArray	DWORD 64 DUP(0)Pause BYTE "pause", 0
Fmt BYTE "%d ", 0.code start:mov eax, Fib1mov ecx, FIBNUMxor edi, edi
L0:mov [dwArray + edi * TYPE dwArray], eaxadd eax, Fib0mov ebx, Fib1mov Fib0, ebxmov Fib1, eaxinc ediloop L0xor edi, edi
L1:invoke crt_printf, OFFSET Fmt, DWORD PTR [dwArray + edi * TYPE dwArray]inc edicmp edi, FIBNUMjz Endingjmp L1Ending:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

6. 数组反向

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.lib.stack 4096.data 
dwArray 	DWORD 15, 21, 34, 49, 52, 98
ArrayLen  DWORD LENGTHOF dwArray - 1Pause BYTE "pause", 0
Fmt BYTE "%d ", 0.code start:mov edi, ArrayLenxor esi, esi mov ecx, 3
L0:mov eax, [dwArray + edi * SIZEOF DWORD]xchg [dwArray + esi * SIZEOF DWORD], eaxxchg [dwArray + edi * SIZEOF DWORD], eaxdec ediinc esi loop L0L3:xor edi, edi
L1:invoke crt_printf, OFFSET Fmt, DWORD PTR [dwArray + edi * TYPE dwArray]inc edicmp edi, LENGTHOF dwArrayjz Endingjmp L1Ending:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

7. 将字符串复制为反向

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.lib.stack 4096.data 
source BYTE "This is the source string", 0
srcLen DWORD ($ - source) / TYPE source  - 2
target BYTE SIZEOF source DUP('$')Pause BYTE "pause", 0
Fmt BYTE "%c", 0.code start:mov ecx, srcLenxor edi, edi
L0:mov al, [source + ecx]mov [target + edi], alinc ediloop L0mov al, [source + ecx]mov [target + edi], alinc edimov BYTE PTR [target + edi], 0
L3:xor edi, edi
L1:invoke crt_printf, OFFSET Fmt, BYTE PTR [target + edi * TYPE target]inc edicmp edi, LENGTHOF targetjz Endingjmp L1Ending:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

8. 数组元素位移

.386
.model flat, stdcall
option casemap:none include windows.inc 
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include msvcrt.inc
includelib msvcrt.lib.stack 4096.data 
dwArray 	DWORD 10, 20, 30, 40, 50, 60
AryLen	DWORD LENGTHOF dwArray - 1TmpCh	DWORD  0Pause BYTE "pause", 0
Fmt BYTE "%d ", 0.code start:mov ecx, AryLenxor edi, edi; 保存最后一个数字mov ebx, [dwArray + TYPE dwArray * ecx]mov TmpCh, ebxdec ecx
L0:mov eax, [dwArray + TYPE dwArray * ecx]inc ecx mov [dwArray + TYPE dwArray * ecx], eaxdec ecx loop L0mov eax, [dwArray + TYPE dwArray * ecx]inc ecxmov [dwArray + TYPE dwArray * ecx], eaxdec ecxmov eax, TmpChmov [dwArray + TYPE dwArray * ecx], eaxxor edi, edi
L1:invoke crt_printf, OFFSET Fmt, BYTE PTR [dwArray + edi * TYPE dwArray]inc edicmp edi, LENGTHOF dwArrayjz Endingjmp L1Ending:invoke crt_system, OFFSET Pauseinvoke ExitProcess, 0
end start

(完)

http://www.lryc.cn/news/167536.html

相关文章:

  • EDA(Exploratory Data Analysis)探索性数据分析
  • Python中的多媒体处理库有哪些?
  • LeetCode【28. 找出字符串中第一个匹配项的下标】
  • 产业互联网开始从简单的概念,逐渐成为可以落地的存在
  • element-ui tree组件实现在线增删改
  • 华为开源自研AI框架昇思MindSpore应用案例:消噪的Diffusion扩散模型
  • 华为CD32键盘使用教程
  • 第三节:在WORD为应用主窗口下关闭EXCEL的操作(2)
  • Layui + Flask | 弹出层(组件篇)(04)
  • Electron和vue3集成(推荐仅用于开发)
  • Vue.js和TypeScript:如何完美结合
  • 034:vue项目利用qrcodejs2生成二维码示例
  • 执行 git remote add github git@github.com:xxxx/testGit.git时,git内部做了啥?
  • Makefile基础
  • 【PickerView案例08-国旗搭建界面加载数据 Objective-C预言】
  • 2023-09-15力扣每日一题
  • 系列七、Nginx负载均衡配置
  • Python爬虫(二十)_动态爬取影评信息
  • 基于 Flink CDC 高效构建入湖通道
  • redis的基础底层篇 zset的详解
  • 数据分享|R语言逻辑回归、线性判别分析LDA、GAM、MARS、KNN、QDA、决策树、随机森林、SVM分类葡萄酒交叉验证ROC...
  • Open3D(C++) 点云旋转的轴角表示法和罗德里格斯公式
  • CPU的三级缓存
  • pgzrun 拼图游戏制作过程详解(6,7)
  • laravel框架 - 集合篇
  • [npm]package.json文件
  • 联表查询 索引 事务 JDBC使用 CPU工作原理 线程概念 Thread类的用法
  • 学习格式化dedecms模版里格式化时间标签pubdate的方法
  • 用思维导图了解《骆驼祥子》的内容
  • js 不同域iframe 与父页面消息通信