Advertisement
kiwser

Reverse

Oct 30th, 2021
1,858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .MODEL SMALL
  2. .STACK 100H
  3. .DATA
  4.  
  5. ; The string to be printed
  6. STRING DB 'B F K L V', '$'
  7.  
  8. .CODE
  9. MAIN PROC FAR
  10. MOV AX,@DATA
  11. MOV DS,AX
  12.  
  13. ; call reverse function
  14. CALL REVERSE
  15.  
  16. ; load address of the string
  17. LEA DX,STRING
  18.  
  19. ; output the string
  20. ; loaded in dx
  21. MOV AH, 09H
  22. INT 21H
  23.  
  24. ; interrupt to exit
  25. MOV AH, 4CH
  26. INT 21H
  27.  
  28. MAIN ENDP
  29. REVERSE PROC
  30.     ; load the offset of
  31.     ; the string
  32.     MOV SI, OFFSET STRING
  33.  
  34.     ; count of characters of the;
  35.     ;string
  36.     MOV CX, 0H
  37.  
  38.     LOOP1:
  39.     ; compare if this is;
  40.     ;the last character
  41.     MOV AX, [SI]
  42.     CMP AL, '$'
  43.     JE LABEL1
  44.  
  45.     ; else push it in the;
  46.     ;stack
  47.     PUSH [SI]
  48.  
  49.     ; increment the pointer;
  50.     ;and count
  51.     INC SI
  52.     INC CX
  53.  
  54.     JMP LOOP1
  55.  
  56.     LABEL1:
  57.     ; again load the starting;
  58.     ;address of the string
  59.     MOV SI, OFFSET STRING
  60.  
  61.         LOOP2:
  62.         ;if count not equal to zero
  63.         CMP CX,0
  64.         JE EXIT
  65.  
  66.         ; pop the top of stack
  67.         POP DX
  68.  
  69.         ; make dh, 0
  70.         XOR DH, DH
  71.  
  72.         ; put the character of the;
  73.         ;reversed string
  74.         MOV [SI], DX
  75.  
  76.         ; increment si and;
  77.         ;decrement count
  78.         INC SI
  79.         DEC CX
  80.  
  81.         JMP LOOP2
  82.  
  83.                
  84.     EXIT:
  85.     ; add $ to the end of string
  86.     MOV [SI],'$ '
  87.     RET
  88.        
  89. REVERSE ENDP
  90. END MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement