printing prompts

hi, i have this reverse string code and i want it so that it will prompt the user to enter a string (eg. Please enter a string:) and then another prompt with the final resul (eg. The reversed string is:) the problem is i don't know how to..

at the moment when you run the program it is just blank (all you do is enter the word and hit enter) - the program works i just can't get the prompts working. the code is:

[code]
#MAKE_EXE#

.model small
.stack 200h

.data
maximum_string_length equ 10
string_to_reverse db maximum_string_length dup (?)
reverse_string db maximum_string_length dup (?)

.code

start:
mov ax,@data
mov ds,ax
mov ah,3fh
mov bx,0
mov cx,maximum_string_length
mov dx,OFFSET string_to_reverse
int 21h
and ax,ax
jz done
mov cx,ax
push cx
mov bx,OFFSET string_to_reverse
mov si,OFFSET reverse_string
add si,cx
dec si

reverseloop:
mov al,[bx]
mov [si],al
inc bx
dec si
loop reverseloop
pop cx
mov ah,40h
mov bx,1
mov dx,OFFSET reverse_string
int 21h
done:
mov ax,4c00h
int 21h
end start
[/code]

Comments

  • [b][red]This message was edited by Bitdog at 2003-10-29 10:31:48[/red][/b][hr]
    :I want my code to prompt the user to enter a string (eg. Please enter a string:)
    :and then another prompt with the final resul (eg. The reversed string is:)
    :the problem is i don't know how to..

    (If you reply to this, delete my message so it's not duplicated please.)
    (hold shift + arrow down & DEL key works ok.)

    Print a message before you do your keyboard input.
    [code]
    ;(.data seg message)
    MSG DB "Enter 10 characters... $"

    ;(.code seg code)
    MOV AH,9 ; function 9
    LEA DX,MSG ; MOV might work too, OFFSET MSG (for Masm)
    INT 21h ; DOS INT, print string untill '$'
    [/code]
    Your also using a FILE I/O interrupt for input,
    AH=0x3F input read from handle, handle 0 = stdin
    AH=0x40 output write to handle, handle 1 = stdout
    Most commonly used to feed a file into a program PROG.COM like this
    PROG < INfile.EXT > OUTfile.EXT
    Although it works for KBD input, but it's not commonly used this way.
    You may want to look into buffered input INT 21 AH=10=0x0A
    and you can use the flush buffer & get input with AH=0Ch interrupt function
    [code]
    .data seg
    BUFFER DB 10 ;max input=SIZE
    COUNT DB 0 ;interrupt 21h stores input count here
    STRING DB " " ;big enough to hold 10 characters=SIZE

    .code seg
    MOV AX,0x0C0A ;function 0x0C flushes the buffer & runs function 0x0A
    LEA DX,BUFFER ;MOV might work too
    INT 21h ;DOS int
    [/code]
    The function AH=9 (above) is your standard write string thingie
    & will write your message, string, reversed string, & exit message.
    but a string requires a '$' ending which you have to add,
    (just like you add a 0=nul ending)

    This code gem sets the cursor position by altering the memory location
    where the cursor position is kept in the BIOS seg at 0040:0050h

    0040
    :0050h is the same address as (since seg is in 16 byte increments)

    0000
    :0450h and the GS seg reg is often free to use as a seg pointer,

    so set GS=0 and you can access the Vector Table & BIOS areas easily.
    At 0000:0450h starts 8 words, which is cursor position
    word1 = row/column for page 0
    word2 = row/column for page 1, etc. So

    XOR AX,AX ;zero out AX
    MOV GS,AX ;got ABS seg 0 reg set
    ;(ABS = ABSolute seg, 16 ABS segs of 0xFFFF in CPU's 1 meg of memory.)
    MOV WORD [GS:0450h],0x0102 ;set row1 column2 for page 0 (edit= h])
    0452h = page 1
    0454h = page 2, etc

    ;Then do your AH=9 INT 21h print string to '$' and it works in DOS
    ;Programs start with AX=0? so set GS at the start ?
    ;or after you XOR AX,AX some where near the start, before you use GS.

    Then check & set Video mode 3
    MOV AL,[GS:0449h] ;current video mode byte in BIOs seg (GS=0)
    MOV BYTE [VMODE],AL ; save it some where [DS:VMODE]
    CMP AL,3 ;check Ralf Browns int list, MEMORY.LST for other address.
    JZ V3isSET
    MOV AX,3
    INT 10h ;set video mode 3, text 80x25 256 color, (128 & up blinks)
    V3isSET: ;restore VMODE at end of code.
    (www.google.com search for Ralf Brown should get you the list files.zips)

    DIR /S /B C: > MYLIST.TXT
    will make you a full hard drive file list. Get STR.COM & STRNOT.COM at
    http://bitdog.home.att/files/nasmenv.zip
    To do almost instant hard drive file searches, you don't even have to know
    the full name of the file, part of the name is fine, or it's directory, or
    it's extension, ok you can be really stupid and it works fine.
    I use it alot..........hahahahahahahahaha
    Make a new MYLIST.TXT now and then (it takes a while, like Win FIND does)
    but the following searches take 1 second each.
    STRNOT.COM finds every line that the input string is NOT in
    reduces the search results file.
    PREFIX.COM will add "DEL " to the start of every line,
    rename it Something.BAT and it will delete every file of a given extension
    on your hard drive for you, COPY, RENAME, WHATEVER, etc

    PUSHF
    CALL FAR [GS:0x0021*4] ; is actually an INT 21h (load AH function first)
    ;it calls the address of INT 21h and since an INT pushes the flags automaticly
    ;you have to do it for a far call cauze the INT has an IRET ending
    ;which POPs the Flags word and RETurns.
    The VECTOR TABLE starts at 0000:0000 and is 256 DWORD address's of the INT's
    so multiply your INT number by 4 and you've got the address of the address
    of the int.
    MOV BX,21h ; find & call INT 21h
    SHL BX,2 ;multiply x 4
    MOV EAX,[GS:BX] ;get INT 21h adr in EAX, is one way. (GS=0)

    Your using AND AX,AX & JZ DONE to check for AX=0 zero input for your INT 21h
    I've never seen it used in code before, OR AX,AX & JZ DONE is commmonly used.
    I checked AND AX,AX and it does appear to set the flags properly for JZ.
    Where did you get the AND AX,AX code ?
    Check & be sure it works under all conditions before
    you decide to put it in your stable, unless you've got it from a pro.

    MOV AX,0xB800 ;direct video memory write, 4 very fast sceen updates
    MOV ES,AX
    MOV DI,(160*2)+10 ;GOTOxy row 2, column 10, page 0 (write/screen position)
    MOV AH,4 ;color red
    MOV CX,[COUNT] ;from input above AX=0x0C0A (could be off by 1?)
    MOV SI,BUFFER ;OFFSET BUFFER from above input
    ZZTOP:
    LODSB ;get AL from DS:SI
    STOSW ;write directly to video memory, Vmode3 a your string in red
    LOOP ZZTOP

    MOV AH,8
    INT 21h ;pause (get key with out echo)
    [green]
    Bitdog
    [/green]





  • thank you so much for your help,

    "Your using AND AX,AX & JZ DONE to check for AX=0 zero input for your INT 21h
    I've never seen it used in code before, OR AX,AX & JZ DONE is commmonly used.
    I checked AND AX,AX and it does appear to set the flags properly for JZ.
    Where did you get the AND AX,AX code ?
    Check & be sure it works under all conditions before
    you decide to put it in your stable, unless you've got it from a pro"

    i got most of that code from searching this forum. i think it was a pro that wrote it, someone had asked for help and that code was the reply.

    thanks again for your help
    alex


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories