汇编语言基础 基于x86处理器3.10编程练习答案

  • Post author:
  • Post category:其他


1.整数表达式计算

.386 
.model	flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD
.code
main PROC
	MOV	EAX,4000h	;A+B
	MOV EBX,1000h
	MOV	ECX,2000h
	MOV	EDX,1500h

	ADD	EAX,EBX	;A+B
	SUB	ECX,EDX	;C-D
	SUB	EAX,ECX	;(A+B)-(C-D)


	INVOKE Exitprocess,0
main ENDP
END main

2.符号整数常量

.386 
.model	flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD

Sunday	=0
Monday	=1
Tuesday	=2
Wednesday=3
Thursday=4
Friday=5
Saturday=6

.data
myDays BYTE Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

.code
main PROC

	INVOKE Exitprocess,0
main ENDP
END main

3.数据定义

.386 
.model	flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD

.data
var1 BYTE 10h
var2 SBYTE -14
var3 WORD 2000h
var4 SWORD +2345
var5 DWORD 12345678h
var6 SDWORD -2342423
var7 FWORD 0
var8 QWORD 1234567812345678h
var9 TBYTE 1000000000123456789Ah
var10 REAL4	-1.25
var11 REAL8 3.2E+100
var12 REAL10 -6.223424E-2343

.code
main PROC

	INVOKE Exitprocess,0
main ENDP
END main

4.符号文本常量

.386 
.model	flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD

one TEXTEQU <"I am">
two TEXTEQU <"litbaizhang">

.data
var1 BYTE one
var2 BYTE two

.code
main PROC

	INVOKE Exitprocess,0
main ENDP
END main

5.AddTwoSum

直接打开文件夹内的lst文件即可。

Microsoft (R) Macro Assembler Version 14.29.30133.0	    09/26/21 11:16:37
A.asm							     Page 1 - 1


				; AddTwoSum.asm - Chapter 3 example.

				.386
				.model flat,stdcall
				.stack 4096
				ExitProcess proto,dwExitCode:dword

 00000000			.data
 00000000 00000000		sum dword 0

 00000000			.code
 00000000			main proc
 00000000  B8 00000005			mov	eax,5				
 00000005  83 C0 06			add	eax,6				
 00000008  A3 00000000 R		mov sum,eax

					invoke ExitProcess,0
 0000000D  6A 00	   *	    push   +000000000h
 0000000F  E8 00000000 E   *	    call   ExitProcess
 00000014			main endp
				end main
Microsoft (R) Macro Assembler Version 14.29.30133.0	    09/26/21 11:16:37
A.asm							     Symbols 2 - 1




Segments and Groups:

                N a m e                 Size     Length   Align   Combine Class

FLAT . . . . . . . . . . . . . .	GROUP
STACK  . . . . . . . . . . . . .	32 Bit	 00001000 DWord	  Stack	  'STACK'	 
_DATA  . . . . . . . . . . . . .	32 Bit	 00000004 DWord	  Public  'DATA'	
_TEXT  . . . . . . . . . . . . .	32 Bit	 00000014 DWord	  Public  'CODE'	


Procedures, parameters, and locals:

                N a m e                 Type     Value    Attr

ExitProcess  . . . . . . . . . .	P Near	 00000000 FLAT	Length= 00000000 External STDCALL
main . . . . . . . . . . . . . .	P Near	 00000000 _TEXT	Length= 00000014 Public STDCALL


Symbols:

                N a m e                 Type     Value    Attr

@CodeSize  . . . . . . . . . . .	Number	 00000000h   
@DataSize  . . . . . . . . . . .	Number	 00000000h   
@Interface . . . . . . . . . . .	Number	 00000003h   
@Model . . . . . . . . . . . . .	Number	 00000007h   
@code  . . . . . . . . . . . . .	Text   	 _TEXT
@data  . . . . . . . . . . . . .	Text   	 FLAT
@fardata?  . . . . . . . . . . .	Text   	 FLAT
@fardata . . . . . . . . . . . .	Text   	 FLAT
@stack . . . . . . . . . . . . .	Text   	 FLAT
sum  . . . . . . . . . . . . . .	DWord	 00000000 _DATA	

	   0 Warnings
	   0 Errors

6.AddVriables程序

; AddVariables.asm - Chapter 3 example.

ExitProcess PROTO
.data
firstval  qword 20002000h
secondval qword 11111111h
thirdval  qword 22222222h
sum qword 0

.code
main proc
	mov	rax,firstval				
	add	rax,secondval		
	add rax,thirdval
	mov sum,rax

	mov ecx,0
	call ExitProcess
main endp
end 



版权声明:本文为Litbai_zhang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。