Question

Write an 8088/8086 assembly program that counts the length of a null terminated string that starts...

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.

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a short RISC-V assembly program that operates on a NULL terminated string of arbitrary size...
Write a short RISC-V assembly program that operates on a NULL terminated string of arbitrary size (use your favourite phrase when you define it with DC for testing). The program (no need to define a function) scans the string and replaces every lower case character with the corresponding upper case. Your program prints the string before and after converting it to upper case.
Write an 8086 assembly language program to initialize counter 2 of 8253 in mode 0 with...
Write an 8086 assembly language program to initialize counter 2 of 8253 in mode 0 with a count of FFAAH.
Write a MIPS assembly program that asks the user first for a string, then for a...
Write a MIPS assembly program that asks the user first for a string, then for a character. The program should search the string for the character and print out the number of times the character appears in the string. Restrictions can be used, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
How to write an X86 assembly program that simply counts how many A’s, C’s, T’s, and...
How to write an X86 assembly program that simply counts how many A’s, C’s, T’s, and G’s the input string contain.
Objectives: ⦁   Declare and initialize null-terminated string ⦁   Apply indirect address ⦁   Write loop ⦁   Apply...
Objectives: ⦁   Declare and initialize null-terminated string ⦁   Apply indirect address ⦁   Write loop ⦁   Apply Irvine.inc library functions to display a string Problem Description: Write a program with a loop and indirect address that copies a string from source to target. Revising the character order in the process. Use the following variables: source BYTE “This is the string that will be reversed”, 0 target BYTE SIZEOF source DUP(‘#’) You may refer to the Programming Exercise #7 on Page 138...
Assembly using "Atmel" : 1- Write a program that counts from 0 to 255 and show...
Assembly using "Atmel" : 1- Write a program that counts from 0 to 255 and show the result on PORTD (shown on 8 LEDs). 2- Write a program that adds two numbers and show their sum on PORTD.
Write a Java program that counts the number of alphabetic ('A' to 'Z' in both upper...
Write a Java program that counts the number of alphabetic ('A' to 'Z' in both upper and lower case) and digit ('1' to '3') characters in a String. The method header is as follows: public static int countNumAlphabetic ( String str ) { } Sample Output: countNumAlphabetic("mA13Th9zB86") returns 8
Write a program in C that extracts the tokens from a string. Given a string as...
Write a program in C that extracts the tokens from a string. Given a string as input, the program should print on the screen each token on a new line. For example given the following string as input: “hello there my friends” the program should generate: I am a programmer
Write a C program that counts the number of repeated characters in a phrase entered by...
Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated” For example: If the phrase is “full proof” then the output will be: Number of characters repeated: 3 Characters repeated: f, l, o Note: Assume the length of the string is 10.
Write a recursive function count_digits that counts all the digits in a string. Program: C
Write a recursive function count_digits that counts all the digits in a string. Program: C
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT