当前位置:网站首页>[assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)
[assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)
2022-07-24 08:57:00 【Strange &】
Catalog :
Preface
How do you do , I am a “ blame & ”, I'm a college student .
Home link : blame & My personal blog home page
️ The main direction of the blog is : Course learning knowledge 、 Homework problem solving 、 Final exam preparation . With the deepening of specialty, it will become more and more extensive … Look forward to .
️ One “ I don't want what I didn't do well to be your regret ” Bloggers .
Nice to meet you , Come on together !
One 、 Experiment description and requirements
1、 Experimental instructions
1、 Through the experimental content 1 Understand the underlying programming .
2、 It is required to define a、b、c、x,a、b、c Unlimited initial value .
3、 The program is executed through debug Modify the parameters a、b、c Value .
4、 The result of the calculation is saved in the variable x in .
2、 The experimental requirements
1、 The experiment purpose .
2、 Simple program flow chart .
3、 Screenshots of memory status and running results during the experiment .
4、 Complete code ( Include necessary notes ).
Two 、 Experimental code
DATAS SEGMENT
; Enter segment code here
a dw +1H ;+1,-2,+3 B^-4AC=4-(12)=-8 b^2-4ac<0, Rootless
b dw -2H ;+1,-4,+4 B^-4AC=16-(16)=0 b^2-4ac=0, There is one
d dw +3H ;+1,-2,-3 B^-4AC=4-(-12)=16 b^2-4ac>0, There are two
x1 dw 1H
x2 dw 1H
DATAS ENDS
STACKS SEGMENT
; Enter the stack segment code here
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
; Code snippet code here
beginning:
mov AX,b ;
IMUL AX ;b^2
MOV CX,AX ;cx=b^2
MOV AX,4 ;ax=4
IMUL A ;ax=4a
IMUL D ;ax=4ac
MOV BX,AX ;bx=4ac
MOV AX,CX ;ax=b^2
SUB AX,BX ;ax=b^3-4ac
cmp AX,0 ;b^<4ac
JL no_answer ; Jump to no_answer
CMP AX,0
JE one_answer ; equal , Jump to ONE_ANSWER
jmp two_answer ; Otherwise jump to two_answer
no_answer:
mov x1,0
mov x2,0
jmp end_work
one_answer: ; When it's worth it :x1+x2=-b/(-2a)
MOV AX,B ;AX:B
MOV BX,A
DIV BX ;AX:B/A
MOV CX,2
DIV CX ;AX:B/(2A)
MOV CX,-1
MUL CX ;AX:-B/(2A)
MOV X1,AX ;X1=-B/(2A)
MOV X2,AX ;X2:-B/(2A)
JMP end_worK
sqrt: ; seek ax Root of
mov bx,+1 ; use bx Compare
mov cx,0 ; use cx Record the number of roots
compute:
SUB AX,BX ;ax-bx
CMP AX,0
JL continue_work ;<0
CMP AX,0
JE equal_cx1 ;=0
;>0
add bx,2 ;bx+2
add cx,1 ; Number of roots +1
;cmp ax,bx ; Compare
;jb continue_work ; When the residual value ax Less than bx when , The number of pieces is cx
;cmp ax,bx ; Compare
;je equal_cx1 ; When the residual value ax=bx when , The number of pieces is cx+1
JMP compute
equal_cx1: ; When the residual value ax=bx when , The number of pieces is cx+1
add cx,1
jmp continue_work
two_answer:
jmp sqrt
continue_work: ;cx: sqrt(b^2-4ac)
mov AX,B ;ax=b
MOV BX,-1
IMUL BX ;AX=-1
add AX,CX ;ax:-b+sqrt(b^2-4ac)
MOV BX,2 ;BX=2
IDIV BX ;ax= [-b+sqrt(b^2-4ac)]/2
mov BX,A ;BX=A
IDIV BX ;ax= [-b+sqrt(b^2-4ac)]/(2a)
MOV X1,AX
mov AX,B ;ax=b
MOV BX,-1
IMUL BX ;AX=-b
sub AX,CX ;ax:-b-sqrt(b^2-4ac)
MOV BX,2 ;BX=2
IDIV BX ;ax= [-b-sqrt(b^2-4ac)]/2
mov BX,A ;BX=A
IDIV BX ;ax= [-b-sqrt(b^2-4ac)]/(2a)
MOV X2,AX
end_work:
jmp beginning ; Jump to the beginning , Re execution
MOV AH,4CH ; sign out
INT 21H
CODES ENDS
END START
3、 ... and 、 Code thinking


Four 、 Program run results
(1)、 unsolvable
a=+1 b=-2 c=+3
b^2-4ac = 4-12 = -8<0
So make x1=0, x2=0
In the memory ,x1、x2 The initial values are as follows :

Command execution : Find jumping to no_answer situation

result : You can see in memory x1=0,x2=0 The calculation is correct

(2)、 A solution (X1 = X2)
a= +1 b = -4 c = +4
b^2-4ac = 16-16=0
x1 = x2 =-2a/b=2
use debug Put... In memory a、b、c、x1、x2 Adjust to 1、-4、4、1、1
According to the running diagram, it can be seen that it has jumped to One_answer The situation .
Result analysis : Multiply by signed numbers , Results the low order is effective .
Available :x1=x2=2, So the calculation is correct .
(3)、 Two different solutions
a =+1 b=-2 c=-3
b^2-4ac=4-(-12)=16>0, All two roots
x1=3
x2=-1
use debug Put... In memory a、b、c、x1、x2 Adjust to 1、-2、-3、1、1
Jump to two_answer situation ( Two different solutions )
Find out b 2 − 4 a c \sqrt {b^2 - 4ac} b2−4ac , The rooting part is :sqrt identification , The result of rooting is saved in CX in 
Find out x1=3
Find out x2=-1 ( Signed number operation , Only the low order is valid , The complement is FF, The true value is -1)
View the results in memory : X1=3 X2=-1
.
5、 ... and 、 Summary of the experiment
In this experiment , I'm familiar with it again DEBUG The startup of and the use of its basic commands , At the same time, the register calling and addressing operations learned in class and practiced in previous experiments will be reviewed and consolidated again , And for assembly language : Sequential programming 、 Branch programming 、 Loop program design has its own understanding and design .
meanwhile , The solution of a quadratic equation of one variable involves the calculation of signed numbers , Therefore, we need to pay attention to the choice of instructions in branch jump and operation ,DIV/IDIV,MUL/IMUL etc. , I learned from the practice of code design and debugging that there are / Operation and storage of unsigned numbers , Be more proficient in flag register and branch jump .
Because the solution of a quadratic equation of one variable has three cases :1、 unsolvable 2、 A solution ( The two solutions are the same ) 3、 The case of two different solutions , And apply it to the cycle 、 Jump 、 Block and other ideas . During the experiment , I have some problems , For example, the order in which assembly code runs 、 Jump 、 The operation result has a symbolic judgment jump, etc , After the teacher's patient answer and my debugging again 、 In practice , Finally, all the experimental requirements were successfully completed , At the same time, carefully record the process and results .
5 month 16 On the afternoon of Sunday 2:30-5:30 Compilation experiment class , I started in the afternoon 2:30 Until evening 9:30, Experienced nearly 100 times of debugging bug And tens of thousands of execution instructions , Finally, the required function is basically completed , But there are still some small places that are not perfect , Then he went to the laboratory three times to improve the code and picture records , Finally, it appears in this blog .
️️️ Don't forget the romantic duck when you are busy Typing Code !
Assembly language is one of my favorite professional courses since I entered the University , It also carries my regret ……
Treasure children must learn well !

边栏推荐
- table-rowspan
- Pulse netizens have a go interview question, can you answer it correctly?
- Unity解决Package Manager“You seem to be offline”
- 使用分区的优点
- JS string interception
- 2、 Encapsulation and tool classes for adding, deleting, modifying and checking in midway
- Tiktok's "online celebrity" was poached by Amazon and broadcast on Amazon live platform
- Tongxin UOS developer account has supported uploading the HAP package format of Hongmeng application
- SQL problem summary
- 我们说的组件自定义事件到底是什么?
猜你喜欢

Realize page return to parent directory based on cookies

Paclitaxel loaded tpgs reduced albumin nanoparticles /ga-hsa gambogic acid human serum protein nanoparticles

VGA character display based on FPGA

Virtual machine terminator terminal terminator installation tutorial

Houdini 官方HDA SideFX Labs 安装

【汇编语言实战】(二)、编写一程序计算表达式w=v-(x+y+z-51)的值(含代码、过程截图)

Ubuntu20.04 install MySQL 5.7

【一起上水硕系列】Final RAD-new literacies

PXE principle and configuration

Taking advantage of the momentum, oceanbase promotes the lean growth of digital payment
随机推荐
[FFH] websocket practice of real-time chat room
Source code analysis of BlockingQueue (arraybq and linkedbq)
03_ UE4 advanced_ illumination
SQL problem summary
RPC调用方如何实现异步调用:CompletableFuture
[Shangshui Shuo series together] June summary +no anxiety +july plan + how to test + how to improve
阻塞队列BlockingQueue 源码解析(ArrayBQ和LinkedBQ)
Optimization of MySQL paging query
JS string interception
Tiktok live broadcast with goods marketing play
在npm上发布自己的库
Valentine's Day
林业调查巡检数据采集解决方案
Four data interaction modes of go grpc
RPC中实现提供者信息变化后通知消费者
超全总结:Go语言如何操作文件
Learn the rxjs operator
TT ecosystem - cross border in-depth selection
情人节
Virtual machine terminator terminal terminator installation tutorial