Strings with nasm assembly 16bit

Thread Starter

fortune2k

Joined Mar 18, 2009
19
Hi i have to make a program to these specs:

So far in stdio.asm you have subroutines which enable you to output and input single characters, and input a word sized number in hex. However, it would be nice to be able to output and input a string of characters.

So write 2 new subroutines which you add to stdio.asm to the following specification:
a)
GetString – inputs a string with echo (into a string in memory i.e. an array of char) from the keyboard until it encounters a cariage return character (note – not a line feed). This is because the <enter> key on the keyboard is encoded as a single carriage return character (not carriage return/linefeed). Thus you cannot look for linefeed as the input termination character.

The carriage return character you have found should not be stored with the rest of the string, it should be discarded. The input string should be placed in an array 256 bytes long. The start address of the destination character array should be passed as a parameter to the subroutine in DI. Very importantly you should ensure that the string of characters you have input is null terminated i.e. as in C put a byte value of 00H into the first byte after the end of the string. The subroutine should not corrupt any register values.

Remember to use the specialist string (array) instructions – although we are unable in this instance to use rep.

Also note that you can use the subroutine Getch that you wrote last week to input individual characters (it should be in stdio.asm).

b)
PutString – outputs to the console window the contents of a character array. The address of the start of the array should be passed to the subroutine in SI. The subroutine assumes that the string is null terminated. You can use the subroutine Putch that you wrote last week to output the individual characters.

c) Write some code in a separate program to test your subroutines. NOTE – PutString like PutHex does NOT output a newline so you will need to do this yourself if you want to put it on separate lines.



i have read all the material which has been given to us in class but i have no idea how to start and approach this any thing you guys can recommended to research?

I am guessing i would have to use some sort of loop with a counter and an array to store the word which has been input from keyboard an array of characters. When printing the out the string to screen you would use a loop again printing out each character in order.

do i have the right idea of how to do this or am i well off here if so can you offer some guidance please.

thankyou :)
 

thatoneguy

Joined Feb 19, 2009
6,359
Allocate memory for the string.

Loop through getc waiting for a keypress. When a character key is pressed, check value for valid character, add to memory, increment pointer. When ENTER is pressed, terminate string with NUL.

To write it back to screen, start at first memory area, get character, print, advance pointer one, test for NUL, if not null, print, repeat until NUL is found in string or variable's memory end is reached.
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
okky i have done some research and i understand how to do it now :) but how do i define the array i have looked everywhere i need like a named array . This is all similar to how C works with strings just an array of characters im after something like this

pseudo:

array [256] ; define arry 256 bytes


GetString:
read char
display char
MOV array[CX] , AL ; moves the value of AL to the array
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
hey i found this but not sure if its right
'MyArray times 256 db 0 ' ... i want to store characters in the array


and then i want to be able to do somthing like 'MOV myarray[CX],DL' soo i can move the char from DL to a part of the array
 
Last edited:
Top