In: Computer Science
Write an 8088/8086 assembly program that counts the length of a null terminated string that starts at location STR.Assume string length will not exceed 255 character.Print the result on the screen?
Step 1
Microprocessor Programming :
The "jargon" of directions which a specific microchip chip has is explicit to that model of chip. An Intel 80386, for instance, utilizes a totally extraordinary arrangement of paired codes than a Motorola 68020, for assigning comparable capacities.
Sadly, there are no principles set up for microchip directions. This makes programming at the most minimal level confounding and concentrated.
At the point when a human developer builds up a lot of guidelines to straightforwardly advise a microprocessor how to accomplish something (like naturally control the fuel infusion rate to a motor), they're customizing in the CPU's own "language." This language, which comprises of exactly the same paired codes which the Control Unit inside the CPU chip disentangles to perform errands, is regularly alluded to as machine language.
While machine language programming can be "phrased" in double documentation, it is regularly written in hexadecimal structure, since it is simpler for people to work with.
Step 2
Code :
PString macro String
local StringLength, StringStart
byte StringLength
StringStart byte String
StringLength = $-StringStart
endm
.
.
.
PString “This string has a length prefix”
; Presumably, ES and DS are set up already
lea si, String1
lea di, String2
mov ch, 0 ;Extend len to 16 bits.
mov cl, String1 ;Get string length.
inc cx ;Include length byte.
rep movsb
include stdlib.a
includelib stdlib.lib
cseg segment para public ‘code’
assume cs:cseg, ds:dseg, es:dseg, ss:sseg
; String assignment procedure
MainPgm proc far
mov ax, seg dseg
mov ds, ax
mov es, ax
lea di, ToString
call StrAssign
byte “This is an example of how the “
byte “StrAssign routine is used”,0
nop
ExitPgm
MainPgm endp
StrAssign proc near
push bp
mov bp, sp
pushf
push ds
push si
push di
push cx
push ax
push di ;Save again for use later.
push es
cld
; Get the address of the source string
mov ax, cs
mov es, ax
mov di, 2[bp] ;Get return address.
mov cx, 0ffffh ;Scan for as long as it takes.
mov al, 0 ;Scan for a zero.
repne scasb ;Compute the length of string.
neg cx ;Convert length to a positive #.
dec cx ;Because we started with -1, not 0.
dec cx ;skip zero terminating byte.
; Now copy the strings
pop es ;Get destination segment.
pop di ;Get destination address.
mov al, cl ;Store length byte.
stosb
; Now copy the source string.
mov ax, cs
mov ds, ax
mov si, 2[bp]
rep movsb
; Update the return address and leave:
inc si ;Skip over zero byte.
mov 2[bp], si
pop ax
pop cx
pop di
pop si
pop ds
popf
pop bp
ret
StrAssign endp
cseg ends
dseg segment para public ‘data’
ToString byte 255 dup (0)
dseg ends
sseg segment para stack ‘stack’
word 256 dup (?)
sseg ends
end MainPgm
Thank you.please vote