References to variables and calls to functions in a program
cseg segment
assume cs:cseg,ds:cseg
org 100
start:
mov bx,word ptr aaa
virus_start:
call get_start
mov ah,4ch
int 21h
get_start:
mov ax,offset virus_start
ret
aaa db ''abcd'',0
cseg ends
end start
After the above program is disassembled.
-u
13E7:0064 8B1E7300 MOV BX,[0073]
13E7:0068 E80400 CALL 006F
13E7:006B B44C MOV AH,4C
13E7:006D CD21 INT 21
13E7:006F B86800 MOV AX,0068
13E7:0072 C3 RET
13E7:0073 61 DB 61
13E7:0074 62 DB 62
13E7:0075 63 DB 63
13E7:0076 64 DB 64
It can be seen that when the program references the variable aaa, it references it through an absolute address.
13E7:0064 8B1E7300 MOV BX,[0073]
8b1e is the operation code, and 7300 is the operand. It can be seen that the operand is an absolute address.
When calling a function
13E7:0068 E80400 CALL 006F,
you may think that call 006f is calling a function through an absolute address.
However, this is after disassembly and has been processed.
What we want to see is the opcode and operand. In this instruction,
the opcode is e8 and the operand is 0400 (that is, 4), which shows that it is the
instruction offset relative to 13E7:006B B44C MOV AH,4C (the next statement of call 006f).
This knowledge is the most basic knowledge to write COM and other viruses
Appendix: Function calls are divided into near, short, and far.
Short is the worst, the called function and the calling point can only have an offset of 128 bytes.
Near can reach 64k (functions in this section can be called), which is enough for COM.
Far can call functions in any segment.
Previous article:How to optimize C language code
Next article:Description of the USB (D12) data communication process between PC and MCU
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Do you know what the future of Wi-Fi is?
- Radio Spectrum Machine Learning System (RFMLS)
- Qorvo's Connection to Wi-Fi
- Edge Detection Methods
- [MSP430F5529 Review] 5. Timer output PWM wave to achieve breathing light
- The difference between various debugging interfaces (SWD, JTAG, Jlink, Ulink, STlink)
- Learn about motors with DDZZ669
- 【AT-START-F403A Review】4. Try 3 ADC synchronous triggering + AN11 simplified code
- Award-winning live broadcast | New requirements for connectors in 5G multi-scenario terminal applications and Molex's 5G connection solutions
- Problems encountered in simulating bridge rectifier using Multisim