News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

printing backwards

Started by Pro32, April 01, 2005, 10:17:27 PM

Previous topic - Next topic

Pro32

Can someone show me how to print backwards. I'm making a program that uses one prompt to as the user for their name: Last Name, First Name. But I want it to print First Name Last Name. How can I go about this.

sluggy

You need to re-word your question... to do it as you've asked is to break the laws of physics, as you want to print something the user hasn't typed yet.....

You need to wait till the user has input their whole name, then you just slice'n'dice the string and output it. You really should write the code first, and then if you still need guidance then ask some more questions.

Tedd

1. Get user's input
2. Check each character in the string until you get to ',' (call this position n)
3. buff[n] = (byte)0
4. print_string(buff[n+2])
5. print_string(buff[0])
6. Learn to do your own homework :bdg
No snowflake in an avalanche feels responsible.

Pro32

Quote from: Tedd on April 02, 2005, 10:44:28 AM
1. Get user's input
2. Check each character in the string until you get to ',' (call this position n)
3. buff[n] = (byte)0
4. print_string(buff[n+2])
5. print_string(buff[0])
6. Learn to do your own homework :bdg


So your saying its very similar to the program I have here. Instead of checking for ',' , I should check for blank spaces. And what is buff?

INCLUDE Irvine32.inc


.data

sentence BYTE "THIS IS MY SECOND ASSIGNMENT!!!"
sentence1 BYTE 30 DUP (?)

.code
main PROC
;this prints the original sentence
mov edx, OFFSET sentence
call WriteString
call Crlf


;Print sentence in  Lowercase letters
mov ecx, LENGTHOF sentence1
mov esi, 0
mov al,0

L1:
mov al, sentence[esi]
cmp esi,0
je NoUpperCase ;for the first symbol

cmp al,41h
jl NoUpperCase ; if less then 'A'

cmp sentence[esi-1],20h  ;checks if previous character was a space
jz NoUpperCase
add al,32d


NoUpperCase:
mov sentence[esi], al
inc esi
loop L1


call WriteString
call Crlf

exit
main ENDP
END main

thomasantony

Hi,
    buff is a memory buffer where the string is stored. and again
Quote
Learn to do your own homework

Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Tedd

Quote from: Pro32 on April 02, 2005, 05:55:47 PM
So your saying its very similar to the program I have here. Instead of checking for ',' , I should check for blank spaces. And what is buff?
  .
  .

Yes, it's a similar kind of thing.
"Buff" is just the name of the buffer/array to store the user's input in. You could just call it "username" or whatever.

Just have a go at it, if you get stuck - no problem; we don't mind helping. But HAVE A GO :P
The best way to learn is to try it and get it wrong and then work out how to fix it :cheekygreen:
No snowflake in an avalanche feels responsible.