Some notes in assembly language (3)

1. Instruction:
mov:
1 Send the data directly into the register
2 Send the contents of one register into another register
3 Send the contents of a memory unit into a register:
mov al, [0]-> (ax) = ((ds) * 16 + 0)
mov ax, [bx]-> Use the data stored in bx as an offset address EA, the segment address SA defaults to ds, send the data at SA: EA to ax Medium, ie (ax) = ((ds) * 16 + (bx))

jmp:
modify cs: ip
jmp 2AE3: 3-> cs = 2AE3H ip = 0003H
jmp ax- > mov IP, ax (there is no such usage)
jmp short s-> go to the label to execute the command (mark transfer Distance) (8-bit displacement)
jmp near ptr-> Similar to the above (16-bit displacement)
jmp far ptr label-> Transition between segments (modify cs: ip with segment address and offset address)
jmp word ptr ds: [ 0]-> (Intra-segment transfer)
jmp dword ptr ds: [0]-> (Inter-segment transfer) High address is segment address, low address is offset address

push
pop

sub:
sub ax, ax-> clear ax [two bytes]-> mov ax, 0 [three bytes]

inc:
content plus one
mov bx, 1
inc bx-> bx = 2

loop:
1.cx--
2. If it is not zero, jump to the label to execute the program
mov cx, 11
s: add ax, ax
loop s

and:
logic and instruction, bitwise AND operation
mov al, 01101110B
and al, 01001010B-> al = 01001010B
or:
bitwise OR operation (same as above)

div:
division instruction:
div byte ptr ds: [0]-> (al) = (ax) / ((ds) * 16 + 0) quotient, (ah) = remainder-> divisor 8bit dividend 16bit
div word ptr es: [0]-> (ax) = ((dx) * 10000H + (ax)) / ((es) * 16 + 0) quotient, (dx) = remainder-> divisor 16 bits, dividend 32 Bit

db / dw:
db (dbyte) defines byte data (8bit), dw defines word data (16bit)
pseudo-instruction dd (ddoubleword):
double word double word data-> dd 1-> occupies two Word (32bit)

Operator dup:
db 3 dup (0)-> define three bytes, the value is 0
db 3 dup (0,1,2)-> define nine bytes, 012012012
db / dw / dd repeat times dup (duplicate data)

Operator offset (compiler processing):
Get the offset address of the label-> start: mov ax, offset start-> mov ax, 0

The machine code of nop occupies 1byte

jcxz:
conditional branch instruction-> jcxz label (if cx = 0 is transferred to the label to execute,! = 0 is executed downward)

ret, retf:
transfer instruction
ret: (IP) = ((ss) * 16 + (sp))
(sp) = (sp) +
2- > pop IP retf: (IP) = ((ss) * 16 + (sp))
(sp) = (sp) +2
(CS) = ((ss) * 16 + (sp))
(sp) = (sp) +2-> pop CS pop IP

call:
push the current IP or CS and IP onto the stack
Transfer-> call label (push the current IP onto the stack and jump to the label to execute the instruction)
call far ptr label-> transfer between segments
16-bit reg
call word ptr memory unit address
call dword ptr
call + ret to form a subroutine

mul:
multiplication instruction another in a 8bit * 8bit al reg in 8 byte units or memory
-> ax results in
16bit * 16bit In another ax in a 16-bit word or memory unit reg
- > Result high bit in dx low bit in ax
mul reg / mul memory unit
mul byte ptr ds: [0]

convention symbol idata means constant (immediate number-> number directly given in assembly instruction)

2. Register
reg (register), sreg (segment register)
reg = {ax, bx, cx, dx, ah, al, bh, bl, ch, cl, dh, dl, sp, bp, si, di}
sreg = {ds, ss, cs, es}

ax:
ah
al
bx
cx
stored program length
dx

si, di cannot be divided into two 8-bit registers . The content pointed to by

cs
ip
[cs: ip] is executed as an instruction.
Example: [m: n] Read the first instruction from m * 16 + n and execute the
ds register :
Segment register, can't directly pass data in.
Can
the address in mov ds, bx ds be used as the segment address of the memory unit
es register:
segment register?

ss: sp at
any time SS: SP points to the top element of the

stack

4. The use of
debug : The difference between the debug and masm interpretation of the mov ax, [0] instruction:
debug is interpreted as a memory unit, but the masm compiler is interpreted as idata (constant)
solution: first pass the address into the register, and then use Access memory in a manner similar to [bx],
or ds: [0]-> mov al, [0]-> mov al, ds: [0]
-r:
view and change the contents of registers
-r ax modify ax data
-d:
view the contents (hexadecimal display memory) memory
-d 1000: 0 [address segment: offset address]
Next command lists the d subsequent content
-e:
for rewriting the memory contents
- e 1000: 0 0 1 2 3 4 5 'a' .....
-u:
check the meaning of machine code (disassembly)
-t:
execute machine code in memory (track execution)
-a:
write machine code
Line-by-line assembly

-p:
1. Use the p command to execute int 21H
2. Use the p command to automatically execute the loop
-g:
execute the program
directly to g 0016-> cs: 0016
-q:
exit debug

5. Source program:
assume cs: codesg
codesg segment

mov ax, 0123H
mov bx, 0456H
add ax, bx
add ax, ax

mov ax, 4c00H
int 21H // The implementation program returns to use p to execute

codesg ends

end
programming (edit)-> 1.asm-> compile (Masm)-> 1.obj-> link (link)-> 1.exe-
> load (command)-> program in memory-> run

debug 1.exe

6. Assembly
Safe space: 0: 200 ~ 0: 2ff (00200h-002ffh)
You can use debug to check whether it is all 0, and then operate the

operating system to allocate memory space:
dw 0123h, 0456h, 0789h, 0abch
data defined by dw Located at the very beginning of the code segment-> CS: 0 position
You can use start to indicate the entry of the program-> start-> end start
Use the stack in the code segment: dw 0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0 (open space)
defines 16 font data as a stack using
mov ax, cs
mov ss, ax
mov sp, 30h-> put the top of the stack ss: sp points to cs: 30h and
puts the code, data and stack into different segments:
assume cs: code, ds: data, ss: stack
data segment
dw 0123h, 0456h ......
data ends
stack segment
dw 0, 0,0,0,0 .....
stack ends
code segment .....-
> mov ax, data The segment address named data is sent to ax for a
more flexible method of defining memory addresses: and. or.
[bx + idata]-> Offset address bx + idata
Example: mov ax, [200 + bx]

Give the data in the form of characters: (ascii)
'xxxx'
mov al, 'x'-> mov al, 61H
db 'unIX'-> db 75H, 6EH, 49H, 58H

In the double loop loop, the data in cx can be saved in bx before proceeding
or in memory. Generally,

only bx, si, di, and bp in the stack can be used in [...] for the memory unit. Addressing (8086cpu)
as long as bp is used in [...], no segment address is explicitly given, the segment address defaults to ss in ss
mov ax, [bp]-> (ax) = ((ss) * 16+ (bp))

Segment address (SA) and offset address (EA)-> default segment address ds, ss

Word operation and byte operation: It
seems that: word operation is generally ax type, byte operation is al type
word ptr / byte ptr:
mov word ptr ds: [0], 1-> indicates that the memory unit accessed by the instruction is a word Unit
mov byte ptr ds: [0], 1-> indicates that the memory unit accessed is a byte unit
(a word unit is two byte units)

7. Other
1byte = 8bit-> 8 binary digits
1byte-> store 2 hexadecimal digits
and / or can change the letter case (bit operation)

Guess you like

Origin www.cnblogs.com/mzi-mzi/p/12731539.html