Assembly Language Program To Read A String And Display

  1. Assembly Language Program To Read A String And Display Two
  2. Write An Assembly Language Program To Read A String And Display Length Of The String
  3. Assembly Language Program To Read A String And Display The Text
  4. Assembly Language Program To Read A String And Display The Table
  5. Assembly Language Program To Read A String And Display The Number

Write an assembly language program (Intel 8086) to READ A STRING, CONVERT IT INTO UPPER CASE AND FINALLY DISPLAY THE CONVERTED STRING

title ALP to read a string, convert it into upper case and display the converted string
dosseg
.model small
.stack 100H
.code
main proc far
mov ax, @data ; initialize ds register
mov ds, ax
mov ah, 0ah ; read string
lea ax, param
int 21h
mov bx, 00 ; convert to upper string
mov cx, act_len
L2: mov ah, str [bx]cmp ah, 41h
jb L1
cmp ah, 51h
ja L1
XOR ah, 00100001B
mov str [bx], ah
L1: inc bx
loop L2
mov ah, 02h ; display newline
mov dl, 0a
int 21h
mov ah, 09h ; display string
lead dx, str
int 21h
mov ax, 4C00H ; return to DOS
int 21H
main endp
.data

What I'm trying to do is get a String input from the user. And then displaying that string. I have no idea how to do it. I have most of the code figured out except that one part. Any help will be greatly appreciated! (By the way I'm just learning Assembly Language. I'm more used to Java). Mahmoud El‐Gayyar / Assembly 5 We write.asm files containing ASCII (i.e., text) versions of our program MASM assembles our.asm file into a.obj file – unlinked, Intel32 binary code All the.obj files are linked to create an executable – a.exe file The.exe file is loaded into main memory, addresses are.

paramlabelByte
max_mendb60
act_lendb?
strdb60 dup(?)


end main

Problem Statement

For this assignment, you are to develop a LC-3 assembly program to read a string provided by theuser, store it in memory and redisplay it on the screen.
A skeleton code is provided to you. The code is missing some lines, which are indicated by the
;________ ;Add a line here to …
For instance, the first code you have to add asks:
;________ ;Add a line here to start your program at address x3000
You should replace this comment with the appropriate asm instruction, so that your program

;________ ;Add a line here to start your program at address x3000
;***************************************
;Part I: Initialize
;***************************************
;We allocated memory for the string already.
LEA r1, str1 ; addr of array to store string
;Why are we using LEA here and not LD or LDI?
AND r3, r3, #0 ; to store the size of the string/array
AND r2, r2, #0
;Prompt user to enter the string
LEA r0, prompt1
;PUTS writes a string of ASCII characters to the console display
;from the address specified in R0.
;Writing terminates with the occurrence of x0000
PUTS
;***************************************
;Part II: Read / Store the string
;***************************************
;
; Start reading characters
;
;GETC is same as TRAP x20: Reads a char and stores its ASCII code in R0
loop GETC ; Read a character.
;ASCII for newline/carriage return is LF and it is stored at #10
;________ ;Add a line here to check if the new char is a carriage return.
BRZ done
out ; echo character
STR r0, r1, #0
ADD r1, r1, #1 ; advance ptr to array
;________ ;Add a line here to increment size of the array
LD r6, EOL
ADD r4, r3, r6 ; check if we reached max length
BRN loop
;***************************************
;Part III: Display the string
;***************************************
done ;________ ;Add a line here to append NULL at the end of string
;Keep the label done. What is the ASCII char for NULL?
;Why are we adding NULL to the end of our string?
;________ ;Add a line here to add a carriage return to your string/array
out
LEA r0, str1
PUTS
HALT
prompt1 .STRINGZ “Enter a string of 30 characters or less. ”
str1 .BLKW 30 ; Allocate memory for chars to be stored
EOL .fill #-29 ; Limit of chars
.end

Solution

.ORIG x3000 ;Add a line here to start your program at address x3000

;***************************************

;Part I: Initialize

;***************************************

;We allocated memory for the string already.

LEA r1, str1 ; addr of array to store string

;Why are we using LEA here and not LD or LDI?

; LEA loads the starting address of the variable into r1, LD would load a value from the string and LDI would load a number

AND r3, r3, #0 ; to store the size of the string/array

AND r2, r2, #0

;Prompt user to enter the string

LEA r0, prompt1

;PUTS writes a string of ASCII characters to the console display

;from the address specified in R0.

;Writing terminates with the occurrence of x0000

PUTS

;***************************************

;Part II: Read / Store the string

;***************************************

;

; Start reading characters

;

;GETC is same as TRAP x20: Reads a char and stores its ASCII code in R0

loop GETC ; Read a character.

Assembly Language Program To Read A String And Display

Assembly Language Program To Read A String And Display Two

;ASCII for newline/carriage return is LF and it is stored at #10

ADD r4,r0,#-10 ;Add a line here to check if the new char is a carriage return.

BRZ done

out ; echo character

STR r0, r1, #0

ADD r1, r1, #1 ; advance ptr to array

ADD r3, r3, #1 ;Add a line here to increment size of the array

LD r6, EOL

ADD r4, r3, r6 ; check if we reached max length

Write An Assembly Language Program To Read A String And Display Length Of The String

BRN loop

;***************************************

;Part III: Display the string

;***************************************

done STR r2, r1, #0 ;Add a line here to append NULL at the end of string

;Keep the label done. What is the ASCII char for NULL?: 0

Assembly Language Program To Read A String And Display The Text

;Why are we adding NULL to the end of our string? PUTS prints all characters in a string until a NULL is found

ADD r0,r2,#10 ;Add a line here to add a carriage return to your string/array

out

LEA r0, str1

PUTS

Assembly Language Program To Read A String And Display The Table

HALT

prompt1 .STRINGZ “Enter a string of 30 characters or less. ”

Assembly Language Program To Read A String And Display The Number

str1 .BLKW 30 ; Allocate memory for chars to be stored

EOL .fill #-29 ; Limit of chars

.end