dos compilation summary

Foreword:

I need to study and assemble the planning textbook, but unfortunately I don’t understand it well. Here I found a learning method for everyone. In fact, it may be difficult for novices to understand some abstract expressions. Here I will record the doubt points and ideas I have learned.

Key points:

Here I will give you an analysis using the question as an example

  1. Output input lowercase letters corresponding to uppercase letters

We need to briefly know the functions of commonly used registers.

1. General registers ax, bx, cx (bound with loop), dx
2. Input and output registers: al (register for input characters), dl register for output characters
3. Instruction register: ah (used for input instructions) Register, if input 1 is input, 2 is output, 4ch is end),

START:
MOV AH,1
INT 21H

CMP AL,'A'
JL A1
CMP AL,'Z'
JG A1

ADD AL,32
MOV DL,AL
MOV AH,2
INT 21H
A1:
    ; 退出程序
    MOV AH, 4Ch       ; AH=4Ch 表示程序退出
    INT 21H           ; 调用 DOS 中断 21H 退出程序
  1. First we need to enter characters. The entered characters are in the AL register by default.
  2. Then we compare, and if the input value is less than the corresponding Ascii value of A or greater than the value of z, we jump to the end flag.
  3. COP connects two numbers, followed by comparison adjustment, to achieve conditional transfer, which is the if statement in C language.
  4. A1 is a custom flag bit, equivalent to a function in C language. Here I define a statement to exit the program.
  5. int21, interrupt signal, equivalent to the necessary process to perform operations.
  6. The function of the Ah register is that storing 1 represents input and storing 2 represents output. This is equivalent to a register that calls system functions and is generally used in conjunction with INT 21.

1. Why do we need to add h after compiling numbers?

In assembly language, adding the "h" suffix is ​​usually used to represent a hexadecimal number. In assembly language, commonly used numerical representations include:

Decimal notation: For example, 10 represents a decimal integer.

Hexadecimal notation: Add the "h" suffix after the value, for example, 10h represents a hexadecimal integer, which is equivalent to 16 in decimal.

Binary notation: Add "0b" or "0B" prefix in front of the value, for example, 0b101 represents a binary integer, which is equivalent to 5 in decimal.

Octal notation: Add a "0" prefix in front of the value, for example, 010 represents an octal integer, which is equivalent to 8 in decimal.

In assembly language, adding the "h"
suffix can help programmers clearly know that a value is represented in hexadecimal, not decimal or other bases. The use of this representation can improve the readability of code, especially when dealing with memory addresses, register values, and other low-level hardware-related values. In most assembly languages, the compiler or assembler can determine the base of a value based on context, but specifying the base explicitly can reduce ambiguity.

For example, 10h represents a hexadecimal number, while 10 might represent a decimal number. This convention helps programmers understand and process data correctly.

Now that you know the basics, you can write a variant question

Output AZ 26 letters

START:
    ; 初始化循环计数器 CX
    mov cx, 26
    mov dl,'A'

loop_start:
    ; 在这里放置循环体的代码
    
    ;输出字符
    int 21h
    ;加1
    add dl,1

    ; 递减循环计数器 CX
    loop loop_start

    ; 循环结束

    ; 退出程序
    mov ah, 4Ch
    int 21h

Guess you like

Origin blog.csdn.net/faker1234546/article/details/132662012