Pages

Tuesday, 26 July 2011

STRING REVERSAL ASSEMBLY PROGRAM for MP lab

  1. ORG 100h
  2.  
  3. MOV si,sp ; Save stack pointer!
  4.  
  5. input_loop:
  6.     XOR ax,ax
  7.     INT 16h ; Use int16 to get a keystroke
  8.  
  9.     CMP al,' ' ; is it a space char?
  10.      JE input_loop ; if space, get another char
  11.  
  12.     PUSH ax ; Save current char on stack top!
  13.     CMP al,13 ; Terminating CR?
  14.      JNE input_loop
  15.  
  16.     POP ax ; Get rid of last pushed char (terminating CR)
  17.      JMP test_stack
  18.  
  19. disp_loop:
  20.     POP dx ; DL will get the pushed char
  21.     MOV ah,2
  22.     INT 21h
  23.  
  24. test_stack:
  25.     CMP si,sp ; Is the stack back where we started?
  26.      JNE disp_loop
  27.  
  28. done: ; So,exit
  29.     MOV ax,0x4C00
  30.     INT 0x21

No comments:

Post a Comment