• 40 Vote(s) - 2.38 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows Console Print
Quote:Instructions: Uses the stdcall calling convention so you can call from C by declaring as 'extern _stdcall _consoleOutput(char *);'. In assembly push a pointer to a zero terminated message and call. No need to clean up the stack afterward.

.model small

str1 db 10h dup(0)                ; will save filename in this
buff db 1h dup(0)                   ; buffer to save data
str2 db 10,13,'File Not Found $'         ; will print this in case file not found

mov ax,@data
mov ds,ax

mov ah,62h                    ; reading psp contents
int 21h

mov es,bx

mov si,0080h                    ; 80h contains the lenght of command tail
mov al,es:[si]
mov cl,al
dec cl

mov si,0082h                    ; 82h starts the text of command tail
lea di,str1                    ; saving it in str1, in this case the filename
mov al,es:[si]
mov [di],al
inc si
inc di
loop read

mov ah,3dh                    ; opening the file using 3dh of int 21h
lea dx,str1                    ; dx contain the filename in ASCIIZ format, i.e 0's at the end
int 21h
jnc mylabel                    ; there is carry generated if any error    

mov ah,09h                    ; printing str2 on error else skip
lea dx,str2
int 21h

mov bx,ax                    ; file handle of the open file is stored in AX, need to move it in BX to read the open the file with handle AX, better store AX somewhere
mov ah,3fh
mov cx,0001h
lea dx,buff                    ; reading data in buff of size 1
int 21h
cmp ax,0000h                    ; printing till ax=0000h, i.e end-of-file
jz end1                        ; will break and jump to end1 label on end of file

mov cx,0001h
lea si,buff                    ; printing data in buff
mov dl,[si]
mov ah,02h                    ; interrupt on print on screen
int 21h
inc si
loop label2
jmp label1

mov ah,4ch                    ; normal end of any assembly program
int 21h
گروه دور همی پارسی کدرز

Forum Jump:

Users browsing this thread: 1 Guest(s)