Assembly Notes(1) Registers

Debug

r : View the current value of all registers; you can also use r <register name> to modify the contents of the register.

d : View the memory content, for example -d 1000:0 8 View the memory content of segment address 1000, offset address 0, and 8 bytes in length.

e : directly modify the memory content: hexadecimal

u : also view the memory content, but it will be translated into assembly instructions and displayed instead of hexadecimal content

a : directly modify the memory content: assembly instructions

t : single-step instruction

p : Jump out of the loop, such as loop and system terminal, or specify an offset address through g to directly execute an instruction.

 

register

CS: Code segment address, which forms a 20-bit actual code physical address by cooperating with IP (offset address). CS:IP points to the instruction currently executed by the CPU.

DS: data segment address, the physical address of the data is determined by manually specifying the offset address; DS cannot be set directly, and needs to be assigned through other registers.

SS: SP determines the position of the top of the stack; when the push and pop instructions are executed, the position of the top of the stack is determined according to SS: SP. The CPU does not know the stack is full and the stack is empty, and the programmer needs to manage it by himself.

CX: Stores the number of cycles and is used in conjunction with the loop instruction.

 

Programming Note

The value in MASM is decimal by default. If you want to write hexadecimal, you must start with 0 or end with h, and 2000 in hexadecimal must be written as 2000h.

All debugs are in hexadecimal, so you can directly write the hexadecimal value, such as 2000,

 

[bx]

In debug you can pass

mov ax,[0]

to read the contents of memory into registers. But in MASM you can only do the following:

mov bx,0
mov ax,[bx]

 Or the following will work as well:

mov ax,ds:[0]
mov bx,ds:[1]
mov cx,ds:[2]
mov dx,ds:[3]

 

code example

; Calculate the sum of the memory values ​​of 0ffff:0 ~ 0ffff:b twelve byte units, and store them in dx 
assume cs: code code segment ; code segment, code is the name of the code side. A program can have many code segments start: mov ax,0ffffh mov ds,ax ; writing data to ds requires the help of other registers, ds: data segment address mov dx, 0 mov cx, 12 ; cx stores the number of loop cycles s: mov bx, 0 ; s is the label loop can jump to the label mov al,[bx] mov ah, 0 add dx,ax inc bx loop s ; after each loop, it will decrement cx by itself until cx is 0 mov ax,4c00h ; these two sentences are standard program exit statements int 21 code ends ; the end of the code segment end start ; end is the end of the program, and start is the program entry

 

safe space

0: 200 ~ 0: 2ff

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324770668&siteId=291194637