Coding on PC: Lesson two - Lesson two: Uploading a file.

Heresy #02
                                                                
###################### ####################                      
######### ########## ######### ###                      
################### ########                                  
######### ######### ####### ###### ##### #######       
######### ########## ####### ###### ###### #       
###################### ######## # ####### #       
######### ##########                                  
######### ########## ###                      
########a$h ####################                      
                                                                
(c) Demiurge Ash                                                
                                                                
    Second lesson: uploading a file.                                
    Explanations are immediately given in the source text.                 
                                                                
;-----------------------------------                           
 .MODEL tiny                                                  
   .CODE                                                        
        ORG 256                                                 
start:;------preparation------                                         
   mov si,80h ;take the command line address (CS)      
   push si; remember                              
   lodsw ;transfer from KS to register ax         
                       ;number of characters and, at the same time, skip   
                       ;first space                           
   xor cx,cx ;zero the register                        
   or cl,al ;if the number of characters in the CS is zero,   
   je error ;then we go to the CS syntax error    
space:                                                          
   lodsb ;character from KS to register ax               
   cmp al,20h ;check for space                      
   je space; if so, skip it                   
 dec si ;decrease the value and                    
   mov dx,si ;remember the KS address in the dx register       
   pop si ;remember the original address of the KS      
   add si,cx ;add to it the length of the entire CS         
   inc si ;go to end of line                 
   mov byte ptr [si],0 ;fill the end of the line                   
;----open file----                                         
   mov ax,ЗdOOh ;preparing a DOS function call;to open a file (read only)      
   int 21h ;function call                           
   jb no_file ;if there is no such file, then go to  
                       ;error opening file                   
;-----file upload---                                         
   mov bx,ax ;in bx the number of the received descriptor      
   mov dx,offset buff ;file load buffer address             
   mov ah,Зfh ;function number                           
   mov cx,8000h ;set the maximum buffer size       
 ;downloads (the file can be downloaded in parts)   
   int 21h ;function call                           
   jb no_file ;if the file is not found, then go to    
                       ;error opening file                   
; file uploaded                                                
; do whatever you want with it ;-)                                  
                                                                
   jmp exit ;to exit                                
;----print messages--                                         
no_file:                                                        
   mov dx,offset Mess2 ;first message address                 
   jmp printerror:                                                          
   mov dx,offset Mess1 ;second message address                 
print:                                                          
   mov ah,9                                                     
 int 21h ;print messages                        
;----EXIT------------                                         
exit:                                                           
   mov ah,Chch                                                   
   int 21h ;exit to DOS                             
;---------------------                                         
Mess1 db 'Command line syntax: SECOND filename.',13,10,'$'     
Mess2 db 'File not found',13,10,'$'                            
buff db 8000h (?)                                             
                                                                
end start                                                       
;-----------------------------------                           
                                                                
    All this can be done in any editor (very convenient for this
built into Dos Navigator), then written to disk, to file c
extension, for example, second.asm                              
    Now,if you have an assembler, you can compile it in
com file. Through the command line we set:                       
    tasmx /m2 second.asm                                        
and get the object file second.obj, link it to .com:       
    tlink /t /x second.obj                                      
and we see a new file second.com - launch it!                 
                                                                
;-----------------------------------                           
    Thanks 4 advices 2 Pyrodex and Dark Lion.                   

Share your thoughts about the article