实验题目1
- 写一个完整的8086汇编语言程序,满足一下要求:
- 数据段申请一个存储数据的字长数据(一个长度为word的变量),该数据存储的值20。
- 数据段申请一个存储数据的字长数据(一个长度为word的变量),该数据的值从键盘输入。
- 将上述两个值自加1后显示在屏幕上。
(代码清单,注意添加注释,养成良好习惯)
(运行结果截图)
实验题目2
- 写一个完整的8086汇编语言程序,求解表达式-3x-y+1的值,结果显示在屏幕上。
(代码清单,注意添加注释,养成良好习惯)
;Program:
;Author:
;Date:
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h ; header file for input/output
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
number1 WORD 20 ;申请空间
number2 WORD ?
prompt BYTE "Enter the secound number: " , 0
prompt2 BYTE cr,Lf
BYTE "The first number is: ",0
prompt3 BYTE cr,Lf
BYTE "The secound number is: ",0
prompt4 BYTE cr,Lf
BYTE "The first number adds 1 is: ",0
prompt5 BYTE cr,Lf
BYTE "The secound number adds 1 is: ",0
string BYTE 40 DUP (?)
Result BYTE 6 DUP (?)
str1 BYTE 40 dup (?)
str2 BYTE 40 dup (?)
.CODE ; start of main program code
_start:
output prompt;
input string,40
atoi string
mov number2,ax
output prompt2
itoa Result,number1
output Result
output prompt3
itoa Result,number2
output Result
inc number1
inc number2
output prompt4
itoa Result,number1
output Result
output prompt5
itoa Result,number2
output Result
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
;Program:
;Author:
;Date:
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h ; header file for input/output
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt1 BYTE "This program will evaluate the expression",cr,Lf,Lf
BYTE " -3x-y+1",cr,Lf,Lf
BYTE "For your choice of integer values.",cr,Lf,Lf
BYTE "Enter value for x: ",0
prompt2 BYTE "Enter value for y: ",0
valuex DWORD ?
valuey DWORD ?
string BYTE 40 DUP(?)
answer BYTE cr,Lf,"The result is "
result BYTE 6 DUP (?)
BYTE cr,Lf,0
.CODE ; start of main program code
_start:
output prompt1
input string,16
atod string
mov valuex,eax
output prompt2
input string,16
atod string
mov valuey,eax
imul eax,valuex
sub eax,valuey
add eax,1
dtoa result,eax
output answer
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code