programming

.model small

.stack 100H

.data

A   db   ‘     This     is     a         test     $’

B   db   100 dup(‘$’)

.code

end

 

Question 1 :

1.1Write a program that counts how many Char spaces does the A string have. You can assume that the string ends with the $ sign.
The answer has to be keep in CX register.

1.2 Write a program that counts how many words the A string have. You can assume that the string ends with the $ sign.
The answer has to be keep in CX register.

1.3 Write a program that copys the String A to an array B. you can assume that the string A ends  with $ sign and the maximum length does not exceed 100 chars including $.

 

Question 2 :

Change the following program ( That can print an integer number in the size of a word ( 16 bit ) , the program bellow can print signed numbers from -32768 to 32767 ) Make the appropriated changes to the program , that we will be able to print unsigned numbers in the size of a word ,the range of the unsigned numbers is : 0 to 65535.

.model  small
.stack   100h
.data
num  dw  -32768
numS db  6 dup(‘ ‘),’$’

.code
mov ax, @data
mov ds, ax

mov ax, num
mov bx, 10

mov si, offset numS+5

next: cwd
idiv bx
cmp dx, 0
jge cont
neg dx
cont:
add dl, 48
mov [si], dl
dec si
cmp ax, 0
jz sof
jmp         next
sof:
cmp num, 0
jge soff
mov byte ptr[si], ‘-‘
soff:
mov ah, 9
mov dx, si
int 21h
.exit

 

Question 3

Given a  one-dimensional array “A” of marked values(signed numbers/values) , the size of a Byte and In the segment code a constant N. Write a program that finds the maximum value in the  array and save it in the last cell of the array  by scanning  the array only ONCE.

comparingadjacent cellsand replacethemif necessary.
The program prints the array at the end of the process.
Fixed value is defined in the data segment as follows:

N equ **VALUE**

Question 4 :

Given a  one-dimensional array “A” of unmarked values(unsigned numbers/values) , the size of a Byte and In the segment code a constant N. Write a program that finds the maximum value in the  array and save it in the last cell of the array  by scanning  the array only ONCE.

comparing adjacent cells and replace them if necessary.
The program prints the array at the end of the process.
Fixed value is defined in the data segment as follows:

N equ **VALUE**

 

 

Question 5 :

Given two one-dimensional  arrays :’A’ and ‘B’, in a fixed size N1, N2 (Constants) which contain marked values ( signed values )sorted in ascending order. In addition, given another one-dimensional array ‘ C’  size N1 + N2. Write program merging the arrays A, B into C. C must be  sorted too. The program will print to the screen the three arrays.

 

Question 6
Given a one-dimensional array of signed numbers . Size of the array is N (fixed). Given  a variable ‘SUM’ that is defined in the data section. In the following sections you will need to sum all the elements of an array and save the answer on Sum under the following requirements:
A. The elements of the array size Byte and the size of the variable Sum is Byte.
B. The elements of the array size Byte and the size of the variable Sum is Word

  1. C. The elements of the array size Word and the size of the variable Sum is Word

Important note:
– In all the clauses the summing ends when you move past all the elements in the array or you get an exception while summing.
– Each section has to be writen  in a separate program.