flat assembler
Message board for the users of flat assembler.
Index
> DOS > Still can't output string after modification, help with C... |
Author |
|
Dex4u 20 Jun 2007, 02:45
Do you mean like this ? :
Code: ; Dos input string +1 demo, by Dex. ORG 100h use16 mov si,message1 ; Point to first message call print ; Call print function call GetCommand ; Call our get sting function mov si,message2 ; Point to second message call print ; Call print function mov si,CommandBuffer ; Point to command buffer call print ; Call print function mov si,message3 ; Point to third message call print ; Call print function xor ax,ax int 16h ; Call wait for keypress mov ax,4C00h int 21h ; Exit to Dos ;====================================================; ; GetCommand ; ;====================================================; GetCommand: pusha ; Save genral regs push es ; Save ES push cs ; Move CS to stack pop es ; Move CS from stack in to ES mov di,CommandBuffer ; Move the address of CommandBuffer in DI mov cx,64 ; move 64 in to counter mov dx,di ; Remember initial offset getkey: xor ax,ax ; Get a key int 16h ; Call interrupt service cmp al,13 ; Enter? je AH_3hd ; Jump = to label AH_3hd cmp al,8 ; Backspace? je backspace ; Jump = to label backspace mov bx,di ; Are we at CX bytes already? sub bx,dx cmp bx,cx jae getkey ; Jump above or = to label getkey mov ah,0Eh ; Write Character mov bx,0x0001 int 10h ; Call interrupt service add al,1 ; Char + 1 stosb ; Record and display keystroke jmp getkey ; Jump to label getkey backspace: cmp di,CommandBuffer ; Compear pointer to start of buffer jbe getkey ; Jump bellow or = to label getkey dec di ; Go back in buffer mov al,8 ; Move cursor back mov ah,0Eh ; Request display mov bx,0x0001 int 10h ; Call interrupt service mov al,32 ; Print a space mov ah,0Eh ; Request display mov bx,0x0001 int 10h ; Call interrupt service mov al,8 ; Move cursor back again mov ah,0Eh ; Request display mov bx,0x0001 int 10h ; Call interrupt service jmp getkey ; Get another key AH_3hd: ; Finish up mov cx,di ; CX = byte count sub cx,dx xor al,al ; Zero-terminate stosb ; Store a byte xor ax,ax ; Success mov si,CommandBuffer ; Move the address of CommandBuffer in SI mov ax,si ; Move SI into AX mov dx,si ; Move SI into DX pop es ; Restore ES popa ; Restore genral regs ret ; Return ;====================================================; ; print. ; ;====================================================; print: mov ah,0Eh ; Request display again1: lodsb ; load a byte into AL from DS:SI or al,al ; Or AL jz done1 ; Jump 0, to label done1 int 10h ; Call interrupt service jmp again1 ; Jump to label again1 done1: ret ; Return message1: db "Please enter a string to be transformed: ",10,13,0 message2: db 10,13, "Result is: ",0 message3: db 10,13, "Press anykey to exit. ",0 CommandBuffer: times 128 db 0 |
|||
20 Jun 2007, 02:45 |
|
LocoDelAssembly 20 Jun 2007, 03:17
Dex, it is not really the same. You're using BIOS ints instead of DOS ints. Normally not a problem but if you want to use redirected both stdin and/or stdout, using BIOS ints will override the redirection while the C++ program will not.
|
|||
20 Jun 2007, 03:17 |
|
Dex4u 20 Jun 2007, 05:02
LocoDelAssembly wrote: Dex, it is not really the same. You're using BIOS ints instead of DOS ints. Normally not a problem but if you want to use redirected both stdin and/or stdout, using BIOS ints will override the redirection while the C++ program will not. Thanks for pointing that out LocoDelAssembly, but i am use to code without OS support . |
|||
20 Jun 2007, 05:02 |
|
Goplat 20 Jun 2007, 15:32
asdf wrote: char* output=""; 2)If you could, the one you're using isn't big enough to hold a line of text anyway. 3)The syntax of the getline that writes to plain char arrays is stream.getline(buffer, maxsize, delimiter). There is also a getline(stream, string, delimiter) function which is for std::string objects - don't get the two confused. This should work: char output[80]; cin.getline(output, 80, '\n'); Quote: for(int i=0; i<strlen(output); i++) for(int i=0; output[i] != '\0'; i++) |
|||
20 Jun 2007, 15:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.