<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">CE</journal-id><journal-title-group><journal-title>Creative Education</journal-title></journal-title-group><issn pub-type="epub">2151-4755</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/ce.2019.107124</article-id><article-id pub-id-type="publisher-id">CE-94063</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Social Sciences&amp;Humanities</subject></subj-group></article-categories><title-group><article-title>
 
 
  Analysis of Several Difficult Problems in Assembly Language Programming
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Wenbing</surname><given-names>Wu</given-names></name><xref ref-type="aff" rid="aff1"><sub>1</sub></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib></contrib-group><aff id="aff1"><label>1</label><addr-line>Fuzhou University of International Studies and Trade, Fuzhou, China</addr-line></aff><pub-date pub-type="epub"><day>04</day><month>07</month><year>2019</year></pub-date><volume>10</volume><issue>07</issue><fpage>1745</fpage><lpage>1752</lpage><history><date date-type="received"><day>21,</day>	<month>May</month>	<year>2019</year></date><date date-type="rev-recd"><day>28,</day>	<month>July</month>	<year>2019</year>	</date><date date-type="accepted"><day>31,</day>	<month>July</month>	<year>2019</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  In assembly language teaching process, Some problems in assembly language 
  programming are difficult to explain. In order to improve the quality of teaching,
   the best way is to verify them by experiments. This paper is an experimental verification of several main problems encountered in the teaching process, and gives a detailed explanation. This paper includes the specific allocation of memory in runtime, the calculation of transfer address in transfer instruction, the differences between hard interrupt and soft interrupt. The purpose of this paper is to provide a clear understanding of the difficult problems in assembly language programming.
 
</p></abstract><kwd-group><kwd>Assembly Language</kwd><kwd> Teaching</kwd><kwd> Address Assignment</kwd><kwd> Interrupt</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>Assembly language is a programming language directly oriented to processors. The processor works under the control of instructions. Each instruction that the processor can recognize is called a machine instruction. Each processor has its own set of instructions that can be recognized, called instruction set. When the processor executes instructions, it takes different actions according to different instructions and completes different functions. It can not only change its internal working state, but also control the working state of other peripheral circuits  (Wang, 2013) .</p><p>Because assembly language has the characteristic of “machine dependence”, when programmers write programs in assembly language, they can fully arrange various resources within the machine, so that they are always in the best use state. The program written in this way has short execution code and fast execution speed. Assembly, language is one of the most closely related and direct programming languages with hardware and the highest efficiency in time and space. It is one of the compulsory courses of computer application technology in Colleges and universities. It plays an important role in training students to master programming technology and familiarize themselves with computer operation and program debugging technology. This paper is the author’s teaching of assembly language course. Several difficult problems encountered here are written for your reference.</p></sec><sec id="s2"><title>2. Assignment of Program Space in Assembler Runtime</title><p>Storage space allocation is needed when assembler runs, which is done by the operating system. When each assembler runs, it first allocates a segment prefix PSP, because DOS uses PSP to communicate with the loaded program.</p><p>PSP is 256 bytes, as shown in <xref ref-type="fig" rid="fig1">Figure 1</xref>. When the executable file is generated to a certain extent, the program is first transferred into memory when it is executed. At this time, the segment address of the program stored in memory is stored in DS. PSP occupies the first 256 bytes of DS:0000H segment. The contents are some instructions of the program, such as how much space the program occupies, etc. Then the real program address is the program address, and CS is pointed here, IP. Setting it to 0000, it is for this reason why CS is 10H larger than DS in general.</p><p>The following is a practical program to observe this effect.</p><p>The program of <xref ref-type="fig" rid="fig2">Figure 2</xref> runs in DEBUG step by step as shown in <xref ref-type="fig" rid="fig3">Figure 3</xref> and <xref ref-type="fig" rid="fig4">Figure 4</xref>. From the execution process of <xref ref-type="fig" rid="fig3">Figure 3</xref>, it can be seen that the address space of the program starts from 075A:0000, followed by the program segment prefix PSP of 256 bytes, followed by the data segment. The address space starts from 076A:0000, the data segment size is 16 bytes, then the stack segment of 16 bytes, and the address space starts from 076B:0000. The address space starts at 076C:0000. Through the above experiments, it can be clearly explained to students how the address space of an assembly language program is</p><p>actually allocated in memory. For example, the following information can be obtained from the above run result graph: when a program has just been loaded into memory and has not yet started running, the DS register stores the starting address of the program segment prefix of the program, and this is the beginning address of the program segment prefix. The address is assigned by the DOS operating system. If the definition order of data segment and stack segment in the program is changed, that is to say, the green part of the above code is put in front of the red code segment, and run as shown in <xref ref-type="fig" rid="fig4">Figure 4</xref>. Compared with <xref ref-type="fig" rid="fig3">Figure 3</xref> and <xref ref-type="fig" rid="fig4">Figure 4</xref>, it can be seen that after changing the order, the program runs only to change the allocation order of the address of the data segment and the stack segment, but the address allocated by the data segment and the stack segment has not changed.</p></sec><sec id="s3"><title>3. Address Calculation of Jump Instructions</title><p>The program is shown in <xref ref-type="fig" rid="fig5">Figure 5</xref>. The result of this program is shown in <xref ref-type="fig" rid="fig6">Figure 6</xref>. As can be seen from <xref ref-type="fig" rid="fig6">Figure 6</xref>, the instruction mov ax, 4c00h; the function of int 21h is simply to point the IP pointer to their next instruction: start: mov ax, 0.</p><p>Using disassembly instructions, <xref ref-type="fig" rid="fig7">Figure 7</xref> is obtained for the above programs. As can be seen from the figure, the physical address of label S1 is 076A:0018H, the physical address of label S2 is 076A:0020H, and the instruction machine code of instruction s2:jmp short S1 is EBF6, in which the meaning of EB is jmp, and F6 represents the jump distance of the instruction. The distance value is calculated as follows: when the CPU reads in the machine code EBF6, the content of its IP pointer points to the next instruction nop. Its physical address is 076A:0022H, and the distance from the address to the physical address 076A:0018H of the label S1 is 10 (decimal system). Because it is a jump up, its value is negative. The</p><p>complement of decimal system-10 is F6, and its address calculation is derived from 0022H + F6H = 0018H.</p><p>076A:0009 memory cells, and their machine codes are 90H, as shown in <xref ref-type="fig" rid="fig8">Figure 8</xref>. Then one-step running of the above program, when running to the instructions mov cs:[di], ax, as shown in <xref ref-type="fig" rid="fig9">Figure 9</xref>, the contents stored in the storage units 076A:0008 and 076A:0009 are programmed with EBF6, as shown in <xref ref-type="fig" rid="fig1">Figure 1</xref>0. Continue to run instruction s0:jmp shorts, then CS and IP become 076A:0008H, then CPU reads machine code EBF6, then IP becomes 0010H. According to the above address jump calculation method, it is concluded that when machine code EBF6 is executed, IP will become 0000H, so the instruction mov ax, 4c00h, int 21h will be executed again, and when the instruction is executed again, the whole program will jump out of the node. Bundle, as shown in <xref ref-type="fig" rid="fig1">Figure 1</xref>1. It can also be seen from the above process that when the instruction mov ax, 4c00h, int 21h is placed at the beginning of the program, its function is only to point the IP pointer to the next instruction address of this instruction, but when this instruction is executed during the execution of the program, it will cause the IP pointer to jump out of the whole program.</p></sec><sec id="s4"><title>4. The Explanation of Hard Interrupt and Soft Interrupt</title><p><xref ref-type="fig" rid="fig1">Figure 1</xref>2 is an assembler program that uses keyboard and screen for input and output. The result is that the number is displayed on the screen when the number is input from the keyboard, and the “*” number is displayed when other characters are input. The results are shown in <xref ref-type="fig" rid="fig1">Figure 1</xref>3.</p><p>Internal interruption means that the CPU does not follow the instructions that have just been executed down, but instead moves on to handle this particular information. External interruption refers to the CPU in the computer system, in addition to the ability to execute instructions and operations, but also should be able to control external equipment, receive their input and output to them. Statements in the program Mov ah, 7, int 21h belongs to function call No. 7 in DOS interrupt, which receives keyboard input information and belongs to soft</p><p>interrupt. Its process is to find the entry address of interrupt program according to int 21h instruction. This interrupt program is used to read keyboard input characters, and the interrupt is triggered by int 21h instruction; instruction in al, 60H is the information read directly into port 60h, and the information of port 60H is the same as that of port 60h. Sample from the keyboard input, the reading process is still to use the same int 21h instruction pointed to the interrupt service program, but this call process is triggered by the keyboard keys caused by the changes in the keyboard internal circuit switch state, belongs to hard interrupt. The substitution of these three instructions well explains the difference and relationship between soft interrupt and hard interrupt  (Wu, Wang, &amp; Liu, 2009;   Qian, 2004) .</p><p>Summary: For beginners, assembly language, because of its close combination with hardware, if their hardware knowledge is not enough, then the course will be more difficult to grasp; For teachers, some of the concepts are particularly difficult to explain clearly, This paper makes a preliminary discussion on some difficult problems in assembly language through examination, including assignment of program space, address calculation of jump instructions and explanation of hard interrupt and soft interrupt, hoping that through a few practical examples, it can be helpful to teachers and students engaged in this teaching work.</p></sec><sec id="s5"><title>Conflicts of Interest</title><p>The author declares no conflicts of interest regarding the publication of this paper.</p></sec><sec id="s6"><title>Cite this paper</title><p>Wu, W.B. (2019). Analysis of Several Difficult Problems in Assembly Language Programming. Creative Education, 10, 1745-1752. https://doi.org/10.4236/ce.2019.107124</p></sec></body><back><ref-list><title>References</title><ref id="scirp.94063-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">Qian, X. J. (2004). Recognition of Assembly Language. Teaching in China University, 47-49.</mixed-citation></ref><ref id="scirp.94063-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">Wang, S. (2013). Assembly Language (3rd ed.). Beijing: Tsinghua University Press.</mixed-citation></ref><ref id="scirp.94063-ref3"><label>3</label><mixed-citation publication-type="journal" xlink:type="simple"><name name-style="western"><surname>Wu</surname><given-names> W.</given-names></name>,<name name-style="western"><surname> Wang</surname><given-names> X.</given-names></name>,<name name-style="western"><surname> &amp; Liu</surname><given-names> X. Y. </given-names></name>,<etal>et al</etal>. (<year>2009</year>)<article-title>. Teaching Reform of Assembly Language Programming</article-title><source> Journal of Southwest Normal University (Natural Science Edition)</source><volume> 34</volume>,<fpage> 201</fpage>-<lpage>204</lpage>.<pub-id pub-id-type="doi"></pub-id></mixed-citation></ref></ref-list></back></article>