Write an 8088/8086 assembly program that counts the length of a null terminated string that starts at location STR. Print the result on the screen.
Greetings!!
Code:Tool used emu8086
org 100h
.data
STR DB "WELCOME TO 8086 PROGRAMMING!!!$" ;load any string of choice
LENGTH DB 10,13,"LENGTH OF THE STRING = $"
.code
mov ax,@data
mov ds,ax
MOV CL,0H ;Initialize register AL with 0 to hold the count of the string
LEA SI,STR ;Loading the address of the string STR into SI
NEXT:
MOV BL,[SI] ;Load one byte from the array to the register BL
CMP BL,24H ;Compare whether the end of string $ reached
JZ END ;If the character read is $,then go to the END label
INC CL ;if the character is not $, then increment the content of register AL ie increment character count
INC SI ;increment the index of the array for reading the next character
JMP NEXT ;Loop back to the label to repeat the steps
END:
;display the message LENGTH OF THE STRING =
MOV DX,OFFSET LENGTH
MOV AH,09H
INT 21H
;converting hex to decimal
MOV AH,0 ;clear ah
MOV AL,CL ;load count into AL
MOV BL,10 ;load 10 to BL for division
DIV BL ;divide AL with BL
XOR AX,3030H ;add 30 to both the bytes of the result in AX to convert it to the ascii equivalent digits
MOV BX,AX ;save into BX
MOV DL,BL ;load MSB of the answer to DL for display
MOV AH,02H ;parameter for display character
INT 21H ;printing the MSB
MOV DL,BH ;load LSB to DL for display
MOV AH,02H
INT 21H ;display LSB
MOV AX,4C00H
INT 21H
loop next
ret
Output screenshots:
Hope this helps
Get Answers For Free
Most questions answered within 1 hours.