Experiment two of assembly language programming

Source: Internet
Author: User

Branch Programming (1)

Experimental content: The memory score buffer contains 100 students ' score data, which is the number of unsigned bytes. Assume that the student's score in [90, 100] interval is excellent, in the [80,90] interval for good, in the [70,80] interval for the general, in the [60,70] interval for passing, in the [0,60] interval is less than, the requirements of statistical failure, passing, general, good and excellent number of people, respectively, sent to Notpassed, Passed, Good, Better, and best byte units. Use the normal jump statement to achieve the above functions.
Analysis: The experimental content is nothing to say. First, a score is placed in a register, and then the results are compared with 60, 70, 80, 90, and then jump to the corresponding branch according to the results of the comparison (corresponding fractional number of +1), 100 cycles can be. The program is mainly to familiarize us with several commonly used conditional transfer directives: JL (less than), JNL (not less than), JG (greater than), JNG (not greater than). There are, of course, other, like unconditional transfer commands, JMP, and so on, that can be used to judge the condition of if, for, and while in a high-level language. Some directives that change status flags, such as CMP, are usually used before these instructions.

Among them, what can be learned in this experiment is. The student variable is defined in the data segment and contains 100-byte elements. This is the same as the concept of arrays in high-level languages. In fact, recalling the high-level language array declaration, but also for the variable to open a contiguous memory space for the array to save data, variable names to save the first address of the group. In assembly language, you can also access the elements of an array by using subscript as a high-level language. For example: You can access the first element via Student[0], access the fourth element through Student[3], and so on. It is important to note, however, that si+1 can be accessed sequentially to the next student element because the student allocates bytes. If the student is assigned a character variable, access will be a little different. When accessing the first element, should be student[0], when accessing the second element, should be student[2], when accessing the third element, it should be student[4] ... Access the first element, or Student[2*i]. This is mainly to consider the difference in memory allocation of bytes and the allocation of words in memory, it can be understood.

The assembly code that implements the feature is as follows:

  

using conditional branching structure to achieve fractional statistics stack segment stack db theDUP (?) stack endsdata segment'Data'Student DB -, the, the, -, -, the, -, A, -, $, -Dup the) notpassed db0Passed DB0Good DB0Better DB0Best DB0Data Endscode Segment'Code'assume Cs:code,ds:data,ss:stackstart:mov ax,data mov ds,ax mov si,0mov cx, -again:cmp Student[si], -JL fun0 CMP Student[si], -JL fun1 CMP Student[si], theJL fun2 CMP Student[si], -JL FUN3 Inc Best JMP donefun0:inc notpassed jmp donefun1:inc Passed jmp donefun2:inc Good JMP donefun3:inc Better jmp donedone:inc si loop again mov bl,good mov cx,8Show:mov ah,02h shl bl,1mov dl,0ADC dl,30hint21H Loop Show mov ax,4c00hint21Hcode ends End start

Experiment two of assembly language programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.