In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The purpose of this article is to share with you about the role of assume in assembly language. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
The function of assume is to associate the segment name with the segment register.
If you define a variable name in the data segment, for example:
X db 0
In your code, you need to use this variable name directly, such as:
Mov al, x
Then, when the assembler assembles, it reports an error.
Because when the variable name x is encountered in the mov instruction, the assembler does not know which segment register it wants to use as the segment address.
So:
If you want to access directly with variable names, or use statement labels (such as the label start in your example), you must associate the segment names of these variables or labels with the segment register name in the assume directive, otherwise an error will occur.
If you do not use the variable name in the segment, you can not associate the segment name with the register.
If you specify a segment to span the prefix when you access the variable, the association is not required. For example, you can access the variable x with mov al, ds:x.
I have been watching Wang Shuang's assembly language these days. But I don't understand the assume directive.
For example, assume cs:code,ds:data has been defined.
However, when observing with debug, it is found that there is no associated data in the ds segment register.
Must be written in cs: mov ax,data
Mov ds,ax then discovers that there is the correct data in ds.
So I wonder, isn't assume already associated with ds?
Go online for help and find the answer.
Writing programs is written for compiling software. Compiled by the software, compiled into machine code, and then to control the CPU. However, compiling software does not generate machine code for assume statements.
Therefore, there must be mov ax,data,mov ds,ax,CPU to be controlled.
-assume statement, which is a pseudo instruction, is only written to the compiling software. Compile the software and do not generate machine code.
Assume only associates the segment name with other segment registers except CS, so that the program can know which segment register to use when accessing the variables in the segment, and does not load the segment address into the segment register when the program loads.
Therefore, the work of loading the segment address into the segment register must be written by the user in the program and execute the code to complete the loading when the program starts to run.
Only for the CS segment register, the segment address is automatically loaded into the segment register when the program is loaded while associating the segment name.
-add: after knowing the answer the day before yesterday, I thought that references like assume ds:data were useless, just for programmers.
But today I found out that's not the case. If you use a label in data, assume ds:data cannot be omitted.
For example:
Data segment
A db 1,2,3,4, 5,6,7,8
B dw 0
Data ends
There is no ":" after "a" b.
If you want to access data with data labels in the cs segment, you must add assume ds:data at the beginning, otherwise an error will be reported.
Arror A2068:Can not address with segment register
But even if you add assume ds:data at the beginning, you can't lose mov ax,data,mov ds,ax in the code snippet.
Function: used to identify the default segment prefix
Explanation: assume does not change the value of segment registers such as ds, but it can change the assembly code generated by the compiler. For example:
Assume ss:stack
Stack segment
X: db 0
Stack ends
If the program needs mov ax, [x], how does the program locate [x]? We know that x is just an offset address 0, so assume is equivalent to telling the compiler that all the labels of the stack segment are associated with ss, so [x] is equivalent to ss: [0]. If we change this sentence directly to mov ax,ss: [0], it is OK not to add assume in front of it. This is why [0] is forced by the compiler to count immediately, while [label] is understood as the content in the label, because the label must be with the segment assume, otherwise it will report an error cannot address with segment register. And [0] if there is no default segment, it can only be considered to be counted immediately.
Therefore, we still need to change the value of ss in the program to stack with instructions, because assume will not modify the segment register, which is determined by the dos system. If the dos system decides to compile the segment value into the .exe file header and modify the segment value according to the file header when loading it into memory, then assume is equivalent to changing the segment value. But the reality I debug is that ds and es point to the exe header (see the 16-bit exe program loading process for details on psp), and ss points to ds+0:00f0,cs and points to ds+0:0100.
The above is the role of assume in assembly language. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.