title  Hello World Program                         (hello.asm)

; This program displays "Hello, world!"

dosseg

.model 	small			;Identifies type of memory model to use

.stack 	100h			; Identifies size of stack segment

.data				;Contains all variables for program
firstmsg    db  'Hi there',0Ah,0Dh,'$'
msg	        db	'Hello World!',0Ah,0Dh,'$'
stringSize  dw  ($ - msg) - 3 ; 

emptyMsg    db	'xxxxxxxxxxxx',0Ah,0Dh,'$'

.code				;Contains all code from program
main  	proc
    mov   	ax,@data	;Required to setup the data segment in the ds register.
    mov   	ds,ax

    ; print out the message first
	mov   	ax,0900h
	mov   	dx,offset firstmsg
    int   	21h

    ; print out the message first
	mov   	ax,0900h
	mov   	dx,offset msg
    int   	21h
    
    ; put the whole thing on the stack
    mov     cx, [stringSize]
    mov     bx, 0     
L1: mov     ah, msg[bx]
    push    ax
    inc     bx
    loop    L1

    ; get the whole thing back from the stack
    mov     cx, stringSize
    mov     bx, 0
L2: pop     ax
    mov     msg[bx], ah
    inc     bx
    loop    L2
    
    ; print out the reversed string
	mov   	ax,0900h
	mov   	dx,offset msg
    int   	21h
    
    ; reversing it again, without the stack
    mov     cx, [stringSize]
    mov     si, 0
    mov     di, [stringSize]
    dec     di 
L3: mov     ah, msg[si]
    mov     emptyMsg[di], ah
    inc     si 
    dec     di
    loop    L3
    
    ; print out the reversed string copied to emptyMsg and reversed again
	mov   	ax,0900h
	mov   	dx,offset emptyMsg
    int   	21h
    
  	mov   	ax,4C00h	;Required to terminate program normally
	int   	21h
main  	endp
end   	main


