Sei sulla pagina 1di 4

19/11/13

File Operations in Assembly Language Mark's blog

File Operations in Assembly Language


The following all use the MS-DOS API (int 21) to do these file operations. (MKDIR) Create Folder

Mark's blog
The art of electronic witchcraft
C : \ > d e b u g a0 1 0 0 x x x x : 0 1 0 0m o va h , 3 9 x x x x : 0 1 0 2m o vd x , 0 1 0 c x x x x : 0 1 0 5i n t2 1 x x x x : 0 1 0 7m o va x , 4 c 0 0 x x x x : 0 1 0 Ai n t2 1 x x x x : 0 1 0 Cd b" C : \ N e w F o l d e r 1 " , 0 0 x x x x : 0 1 1 A nm a k e f . c o m rc x C X0 0 0 0 : 0 0 1 a w W r i t i n g0 0 1 Ab y t e s . q ; C r e a t ef o l d e rf u n c . ; P o i n t st op a t h n a m e ; D oi t ; A H = E x i t ,A L = E r r o r l e v e l ; D oi t ; N u l lt e r m i n a t e dp a t h n a m e

Home About

Remove Folder

C : \ > d e b u g a0 1 0 0 x x x x : 0 1 0 0m o va h , 3 a x x x x : 0 1 0 2m o vd x , 0 1 0 C x x x x : 0 1 0 5i n t2 1 x x x x : 0 1 0 7m o va x , 4 c 0 0 x x x x : 0 1 0 Ai n t2 1 x x x x : 0 1 0 Cd b" C : \ O l d F o l d e r 1 " , 0 0 x x x x : 0 1 1 A nr m v f . c o m rc x C X0 0 0 0 : 0 0 1 a w W r i t i n g0 0 1 Ab y t e s . q ; R e m o v ef o l d e rf u n c . ; p o i n t st op a t h n a m e ; D oi t ; E x i tf u n c . ,A L = E r r o r l e v e l ; D oi t ; N u l lt e r m i n a t e dp a t h n a m e

Create/Truncate File

C : \ > d e b u g a0 1 0 0 x x x x : 0 1 0 0m o va h , 3 c x x x x : 0 1 0 2m o vc x , 2 x x x x : 0 1 0 5m o vd x , 0 1 0 f x x x x : 0 1 0 8i n t2 1 x x x x : 0 1 0 Am o va x , 4 c 0 0 ; C r e a t ef i l ef u n c . ; A r c h i v ef i l ea t t r i b u t e ; P o i n t st of i l e n a m e ; D oi t

jakash3.wordpress.com/2010/02/20/file-operations-in-assembly-language/

1/11

19/11/13

File Operations in Assembly Language Mark's blog


x x x x : 0 1 0 Di n t2 1 x x x x : 0 1 0 Fd b" C : \ U s e r s \ j a k a s h 3 \ n e w f i l e 1 . t x t " , 0 0 nm k f . c o m rc x C X0 0 0 0 : 0 0 2 D w W r i t i n g0 0 1 Ab y t e s . q

Note: File attributes are specified by the hex value of a bit array.

+ + + + + + + + + |?|?|?|0|0|?|0|0| + + + + + + + + +

0 Read Only 1 Hidden 2 System 3 Volume label (ignored) 4 Reserved, must be zero (directory) 5 Archive 6 Unused 7 Unused A Read-Only Archive file: 10000100 In hex that would be: 84 So 84 would be the value for CX in the 3C function of Int 21. Open File

C : \ > d e b u g a0 1 0 0 x x x x : 0 1 0 0j m p0 1 1 c x x x x : 0 1 0 2d b" C : \ U s e r s \ j a k a s h 3 \ d a t a . t x t " , 0 0 x x x x : 0 1 1 Cm o va h , 3 d x x x x : 0 1 1 Em o va l , 4 0 x x x x : 0 1 2 0m o vd x , 0 1 0 2 x x x x : 0 1 2 3i n t2 1 ; O p e nf i l ef u n c . ; B i tf i e l df o rr e a d / w r i t ea c c e s s ; P o i n t st of i l e n a m e ; D oi t

File access mode bit fields for this function:

+ + + + + + + + + |?|?|?|0|0|0|0|0| + + + + + + + + +

000 Read Only (mov cl,0) 001 Write Only (mov cl,20) 010 Read/Write (mov cl,40)
jakash3.wordpress.com/2010/02/20/file-operations-in-assembly-language/ 2/11

19/11/13

File Operations in Assembly Language Mark's blog

After the interrupt call, AX should contain the file handle if no errors occurred. Close File

C : \ > d e b u g a0 1 0 0 x x x x : 0 1 0 0j m p0 1 1 c x x x x : 0 1 0 2d b" C : \ U s e r s \ j a k a s h 3 \ d a t a . t x t " , 0 0 x x x x : 0 1 1 Cm o va h , 3 d x x x x : 0 1 1 Em o va l , 4 0 x x x x : 0 1 2 0m o vd x , 0 1 0 2 x x x x : 0 1 2 3i n t2 1 x x x x : 0 1 2 5m o vb x , a x + x x x x : 0 1 2 7m o va x , 3 e 0 0 / x x x x : 0 1 2 Ai n t2 1 ; D oi t ; C l o s ef i l ef u n c t i o n< ; O p e nf i l ef u n c t i o n ; B i tf i e l df o rr e a d / w r i t ea c c e s s ; P o i n t st of i l e n a m e ; D oi t ; M o v ef i l eh a n d l et oB Xf o r3 ef u n c t i o n-

Read from file

C : \ > d e b u g x x x x : 0 1 0 0j m p0 1 2 b x x x x : 0 1 0 2d b" C : \ U s e r s \ j a k a s h 3 \ a b . t x t " , 0 0; f i l e n a m et or e a df r o m x x x x : 0 1 1 Ad b0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 0 0 , 2 4; ' $ ' t e r m i n a t e d1 0b y t eb u f f e r x x x x : 0 1 2 Bm o va h , 3 d x x x x : 0 1 2 Dm o va l , 0 0 x x x x : 0 1 2 Fm o vd x , 0 1 0 2 x x x x : 0 1 3 2i n t2 1 x x x x : 0 1 3 4m o vb x , a x x x x x : 0 1 3 6m o va x , 3 f 0 0 x x x x : 0 1 3 9m o vc x , 1 0 x x x x : 0 1 3 Cm o vd x , 0 1 1 a x x x x : 0 1 3 Fi n t2 1 x x x x : 0 1 4 1m o va x , 0 9 0 0 x x x x : 0 1 4 4m o vd x , 0 1 1 a x x x x : 0 1 4 7i n t2 1 x x x x : 0 1 4 9m o va x , 4 c 0 0 x x x x : 0 1 4 Ci n t2 1 x x x x : 0 1 4 E r c x C X0 0 0 0 : 0 0 4 e nr e a d f i l e . c o m w W r i t i n g0 0 0 4 Eb y t e s q ; O p e nf i l ef u n c t i o n ; R e a d O n l yf i l ea c c e s s ; P o i n t st of i l e n a m e ; D oi t ; M o v er e t r i e v e df i l eh a n d l ei n t oB X ; R e a df r o mf i l ef u n c t i o n ; R e a dt h ef i r s t0 x 1 0b y t e so ff i l e ; A d d r e s so fb u f f e rt os t o r eb y t e sr e a d ; D oi t ; P r i n ts t r i n gf u n c t i o n ; P o i n t st o' $ 't e r m i n a t e ds t r i n gt op r i n t ; D oi t ; E x i tf u n c t i o n( A L = E r r o r l e v e lt or e t u r n ) ; D oi t

Write to file:

C : \ > d e b u g x x x x : 0 1 0 0j m p0 1 0 1 x x x x : 0 1 0 2d b" C : \ U s e r s \ j a k a s h 3 \ a b . t x t " , 0 0 x x x x : 0 1 1 Ad b" h e l l ow o r l d ! " , 0 0 x x x x : 0 1 2 7m o va h , 3 d x x x x : 0 1 2 9m o va l , 2 0 ; O p e nf i l ef u n c t i o n ; W r i t e O n l yf i l ea c c e s s

x x x x : 0 1 2 Bm o vd x , 0 1 0 2; P o i n t st of i l e n a m e

jakash3.wordpress.com/2010/02/20/file-operations-in-assembly-language/

3/11

19/11/13

File Operations in Assembly Language Mark's blog


x x x x : 0 1 2 Ei n t2 1 x x x x : 0 1 3 0m o vb x , a x ; D oi t ; M o v er e t r i e v e df i l eh a n d l ei n t oB X

x x x x : 0 1 3 2m o va x , 4 0 0 0; W r i t et oF i l ef u n c t i o n x x x x : 0 1 3 5m o vd x , 0 1 1 a; P o i n t st od a t at ow r i t e x x x x : 0 1 3 8m o vc x , 0 d x x x x : 0 1 3 Ai n t2 1 x x x x : 0 1 3 Fi n t2 1 x x x x : 0 1 4 0 rc x C X0 0 0 0 : 0 0 4 0 nw f i l e . c o m w W r i t i n g0 0 4 0b y t e s . q ; N u m b e ro fb y t e st ow r i t e ; D oi t ; D oi t

x x x x : 0 1 3 Cm o va x , 4 c 0 0; E x i tf u n c t i o n

Delete file:

C : \ > d e b u g a0 1 0 0 x x x x : 0 1 0 0m o va h , 4 0 x x x x : 0 1 0 5i n t2 1 x x x x : 0 1 0 Ai n t2 1 x x x x : 0 1 2 4 rc x C X0 0 0 0 : 0 0 2 4 nd e l f . c o m w W r i t i n g0 0 2 4b y t e s . q ; D e l e t ef i l ef u n c t i o n ; D oi t ; D oi t x x x x : 0 1 0 2m o vd x , 0 1 0 c; P o i n t st of i l e n a m e x x x x : 0 1 0 7m o va x , 4 c 0 0; E x i tf u n c t i o n x x x x : 0 1 0 Cd b" C : \ U s e r s \ j a k a s h 3 \ a b . t x t " , 0 0

Share this: Like this:

Google

Facebook 7

Reddit

Like
Be the first to like this.

Related Locks In "Coding" Another simple HTTP server In "C/C++" Getting file descriptor type In "C/C++"

Posted on February 20, 2010 by jakash3. This entry was posted in Assembly, Coding and tagged assembly file, cmd, cmd debug, cmd.exe debug, cmd.exe debug.exe, command prompt debug.exe, debug mode example, debug tut, debug tutorial, debug.exe, debug.exe assembler, debug.exe tutorial, file operations in assembly, jakash3. Bookmark the permalink.

Programming Software

Msgbox in Batch Files

jakash3.wordpress.com/2010/02/20/file-operations-in-assembly-language/

4/11

Potrebbero piacerti anche