Advertisement
Redxone

[ASM x86] - Simple reading program.

Sep 22nd, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .stack 100h
  3. SETPOS macro X,Y
  4.   MOV AH, 2H
  5.   MOV DL, Y
  6.   MOV DH, X
  7.   INT 10H
  8. ENDM
  9. PRT macro STR
  10.   MOV AH, 9H
  11.   MOV DX, OFFSET STR
  12.   INT 21H
  13. ENDM
  14. STRAPPEND macro CH
  15.   MOV CL, BUFFLEN
  16.   MOV DL, CH
  17.   CALL SUBSTR
  18. ENDM
  19.  
  20.  
  21.         .data
  22. mip DB 'Hallo werld!$'
  23. BUFFMAX DB 40
  24. BUFFLEN DB 1
  25. app DB 40 DUP(?),'$'
  26.         .code
  27. MOV AX, @DATA
  28. MOV DS, AX
  29. MOV DI, OFFSET mip
  30. INC DI
  31. MOV BYTE PTR[DI], 'e'
  32. GETINP:
  33.   MOV AH, 1H
  34.   INT 21H
  35.   CMP AL, 0DH
  36.   JE INPEND
  37.   STRAPPEND AL
  38.   JMP GETINP
  39. INPEND:
  40.   CMP BUFFLEN, 41
  41.   JL EXITP
  42.   STRAPPEND '$'
  43. EXITP:
  44.   PRT app
  45.   MOV AH, 4CH
  46.   INT 21H
  47.  
  48. ;------- CALL STATEMENTS --
  49. SUBSTR PROC
  50.  ; TAKES CL AS CH INDEX, AND DL AS CHAR
  51.   LEA DI, app
  52.   MOV BL, 0
  53.   SUBNXT:
  54.     INC DI
  55.     INC BL
  56.     CMP CL, BL
  57.     JE SUBDONE
  58.     JMP SUBNXT
  59.   SUBDONE:
  60.     MOV BUFFLEN, CL
  61.     INC BUFFLEN
  62.     MOV BYTE PTR[DI], DL
  63.   RET
  64. SUBSTR ENDP    
  65. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement