China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 11:26
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Let me show you how raw machine instructions run, hehe! View 1,258 Replies 14
Original Poster Posted 2003-10-30 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
;***************************************************
;A must-read assembly program for beginners moving to the next level
;Author: xy_god
;*********************Stack Segment************************
STACK_SEG SEGMENT STACK

STACK_SEG ENDS
;**********************Data Segment***********************
DATA_SEG SEGMENT PARA
ABSCODE DB 00h,0Dh,0B4h,09h,00h,0Fh;machine instruction code
DB 0B0h,2Ah,00h,11h,0B7h,00h
DB 00h,13h,0B3h,0DAh,00h,15h
DB 0B9h,05h,00h,00h,18h,0CDh,10h
DATA_SEG ENDS
;******************Code Segment***************************
CODE_SEG SEGMENT PARA
MAIN PROC FAR
ASSUME CS:CODE_SEG,DSATA_SEG
ASSUME SS:STACK_SEG
START:
MOV AX,STACK_SEG
MOV SS,AX
MOV SP,0000h
MOV AX,DATA_SEG
MOV DS,AX
;---------------Unconventional code------------------
MOV AX,SEG ABSCODE
PUSH AX
MOV AX,OFFSET ABSCODE
PUSH AX
RET
;-----------------------------------------
MOV AX,4C00H
INT 21H
MAIN ENDP
CODE_SEG ENDS
;******************End of program************************
END START
临河居士
http://www.xygod.pc5.org
Floor 2 Posted 2003-10-30 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
Let me explain: I wrote this program specially for people who don't know what machine code is! This program is very simple: it writes the corresponding machine instructions into the data segment, and then when the program runs, it jumps into those machine instructions!
临河居士
http://www.xygod.pc5.org
Floor 3 Posted 2003-10-30 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
Oh right, what do you all think of my program's readability? Hehe! Please give me more valuable suggestions!
临河居士
http://www.xygod.pc5.org
Floor 4 Posted 2004-05-15 00:00 ·  中国 海南 澄迈县 电信
初级用户
Credits 146
Posts 11
Joined 2003-07-29 00:00
22-year member
UID 7717
Gender Male
Status Offline
For beginners, each line should also be annotated.
Floor 5 Posted 2004-05-16 00:00 ·  中国 浙江 台州 电信
中级用户
★★
Credits 447
Posts 126
Joined 2004-02-10 00:00
22-year member
UID 17150
Gender Male
Status Offline
The addressing mode of Call is basically the same as jmp, but in order to return from the subroutine, before jumping this instruction pushes the address of the instruction immediately following it onto the stack. If it is an intrasegment call (the target address is a 32-bit offset), then what gets pushed is also just an offset. If it is an intersegment call (the target address is a 48-bit full address), then the full address of the next instruction is also pushed. Likewise, if an intersegment transfer involves a change in privilege level, then there is a series of complex protection checks.

Corresponding to this, the retn/retf instructions return from the subroutine. They take the return address from the stack (pushed there by the call instruction) and jump to that address to execute. retn takes a 32-bit offset for an intrasegment return, and retf takes a 48-bit full address for an intersegment return. retn/f can also take an immediate value as an operand; this value is actually the number of parameters passed to the subroutine on the stack (counted in words). After returning, it automatically adds the specified number *2 to the stack pointer esp, thereby discarding the parameters on the stack. The specific details here will be left for the next article.

Although call and ret are designed to work together, there is no necessary connection between them. That is to say, if you directly use the push instruction to push a value onto the stack, and then execute ret, it will likewise treat the value you pushed as a return address and jump there to execute. This kind of abnormal control transfer can be used as an anti-tracing technique
从来不用别人的东西,要用,也先改成自己的再说!
Floor 6 Posted 2004-05-17 00:00 ·  中国 山东 日照 联通
钻石会员
★★★★★
Credits 10,046
Posts 3,039
Joined 2002-11-11 00:00
23-year member
UID 223
Gender Male
Status Offline
1010101011101010101010010101010111010101010110100101010101010101011110100101010101010101010101010101010101010101010101010101010000101010
Now that's what you call machine instructions, BD.
简单就是美
Floor 7 Posted 2004-05-18 00:00 ·  中国 湖北 武汉 电信
初级用户
Credits 112
Posts 3
Joined 2004-05-18 00:00
22-year member
UID 24651
Gender Male
Status Offline
OP, this is clearly assembly; it's still two jumps away from machine instructions.

But the data segment in it does contain machine instructions, so it still fits the thread's intent ^_^

The ret is used very cleverly

Floor 8 Posted 2004-05-21 00:00 ·  中国 辽宁 朝阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
I agree with the opinion of post #6. Real machine code gives people a headache just from looking at it.

For example, the following hexadecimal code:

B4 30 CD 21



熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 9 Posted 2004-05-21 00:00 ·  中国 天津 南开区 联通
高级用户
★★
Credits 924
Posts 243
Joined 2003-07-09 00:00
22-year member
UID 6612
Gender Male
Status Offline
Why set up an empty stack segment?
Wouldn't that cause problems?
Floor 10 Posted 2004-05-25 00:00 ·  中国 湖北 武汉 电信
初级用户
Credits 112
Posts 3
Joined 2004-05-18 00:00
22-year member
UID 24651
Gender Male
Status Offline
Post #5 already analyzed this program very clearly. Friends who think the OP doesn't know what machine instructions are, please read the reply in post #5 first before saying anything more. (Take a close look at the data segment.)
Floor 11 Posted 2004-05-25 00:00 ·  中国 北京 中移铁通
高级用户
★★
游客隐者
Credits 893
Posts 201
Joined 2004-04-27 00:00
22-year member
UID 23335
Gender Male
Status Offline
Aside from not being able to understand it, I can understand everything else
^-^ 党和国家教导我们,看帖一定要回帖,做一个文明的网民.
Floor 12 Posted 2004-05-25 00:00 ·  中国 浙江 宁波 鄞州畅联信息技术有限公司
初级用户
Credits 122
Posts 6
Joined 2004-05-23 00:00
22-year member
UID 25102
Gender Male
Status Offline
Why is the last line of the unconventional code RET instead of RETF.
Floor 13 Posted 2004-06-02 00:00 ·  中国 黑龙江 大庆 联通
初级用户
Credits 131
Posts 12
Joined 2004-03-02 00:00
22-year member
UID 18948
Gender Male
Status Offline
Some people, this really is assembly.
However, the code already shows this: put machine code into the data segment, then jump into the data segment to execute the instructions.

So what do you think machine instructions are? Should microinstructions be brought up too~~
Floor 14 Posted 2004-06-03 00:00 ·  中国 辽宁 丹东 联通
中级用户
★★
Credits 316
Posts 74
Joined 2004-03-04 00:00
22-year member
UID 19167
Gender Male
Status Offline
I recognize all the letters and numbers, but I don't understand anything else
Floor 15 Posted 2004-06-03 00:00 ·  中国 河北 秦皇岛 联通
中级用户
★★
Credits 258
Posts 58
Joined 2003-10-11 00:00
22-year member
UID 11070
Gender Male
Status Offline
Maybe this tool will be useful to everyone………………
http://jihao1234567.go.nease.net/MNEMONIX.exe
Please use a download tool, single thread.
This thing might be of some use.
Seems to explain machine language code………………
奋发向上!!!
Forum Jump: