Monday, March 26, 2012

to print the string length in assembly X86

; to print the string length
;----------------------------------------------------------------------------
.model small

.data
message_display macro msg
mov dx,offset msg
mov ah,09h
int 21h
endm

msg1 db 10,13, "Enter the String $"
msg2 db 10,13, "String is$"
msg3 db 10,13, "$"
msg4 db 10,13, "String Length is$"
string db 10h dup(0)

.code
mov ax,@data
mov ds,ax

message_display msg1

lea si, string
mov bh,00h

accept_nxt_char:
mov ah,01h
int 21h

mov [si],al
inc si
inc bh
cmp al,0dh
jnz accept_nxt_char

mov al,24h
mov [si],al

message_display msg2
message_display msg3
message_display string
message_display msg4
message_display msg3

dec bh
mov cl,04
mov bl,bh
mov dh,02h
shr bl,cl

print: and bl,0fh
cmp bl,09h
jbe dnt_add
add bl,07h
dnt_add: add bl,30h
mov dl,bl
mov ah,02h
int 21h
dec dh
mov bl,bh
jnz print

mov ah,4ch
int 21h

end

;-----------------------------------------------------------------------------------------
; done by prof. Dhumane A.V. VIIT, Pune

No comments:

Post a Comment