flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
daluca 06 Nov 2005, 07:36
Code: org 100h start: mov dx, hl_text mov ax, 0900h int 21h ;up to this point everything is O.K. ;you get the message displayed right? input_string_here: ;here begins the problem wen you get here mov ax, 0A00h ;dx holds the offset of the first message(hl_text) int 21h ;but it should contain the offset of a buffer whith ;2 leading bytes: one for you to tell to int 21h how ;many characters maximum you want to get and the other ;to let int 21h tell you how many characters actually got ;but you already new that rigth? beacouse you add 2 to ;dx to jump over thos bytes. ;so if I put ABCD and press the enter key your hl_text looks ;like this: db 50h,04h,'ABCD'0Dh.... ;50h is the byte representing the 'P' of 'Please....' wich is 80 decimal,with this ;tou told int 21h that you want maximum 80 characters, the 04h is the ;number of characters that the function got: 'ABCD' and the 0Dh is the enter ;key dispaly_ye_text: add dx, 02h ;here you set the dx to the 'ABCD' beacouse you are push dx ;skiping thous bytes and saving the dx right? mov dx, ye_text ;this is no problem, you make the dos mov ax, 0900h ;jump to a new line and print the message ye_text int 21h display_output: ;this is another problem,ah still holds 09h and int 21h pop dx ;prints the message in the current cursor position int 21h ;but wen it gets to print the 0Dh character the function ;understand it as carriage return(so it goes back to the ;beginning of the line and keps printing from there ;so thats why your string gets overwritten getch: mov ax, 0700h ;getch() in TC int 21h ;well this part just waits for a key to exit rigth? mov ax, 4C00h int 21h hl_text db 'Please Enter a string: ', 24h ye_text dd 0A0Dh; db 'You entered the string: ', 24h ;so as you can see the mayor problem is that 0Dh character if you want ;to print the string directly need to get ride of it or make shure nothing ;gets printed after that character this is an idea: org 100h mov dx,hl_text mov ax,900h ;the first message gets printed int 21h ;-------------------------- mov dx,buffer -2 ;remember those two bytes mov ax,0a00h int 21h ;----------------------- mov dx,ye_text ;here we print the other text mov ax,900h int 21h ;------------------------------ mov dx,buffer ;and we print the captured text int 21h ;------------------------- mov ax, 0700h ;getch() in TC int 21h mov ax, 4C00h int 21h hl_text db 'Please Enter a String: ' ,24h ye_text dd 0d0ah db 'You entered the string: ',24h db 40 ;40 bytes maximum db 0 ;here the function will put number of characters entered buffer db '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' ; $ is the terminated character of int 21h so wen we put oir name ;it will be written at the begining of buffer and at the end there will be a ;0dh that will make the cursor go to the begining of the line but nothing ;will be overwritten beacouse the next character of that 0dh will be for sure ;a $ that will make the function stop ;I put 40 in buffer-2 ,but I did not count the $ characters this is just ;an example ;i hope i help sorry for the english [editpost:Matrix](its a little easier to read in code tags)[/editpost] |
|||
![]() |
|
daluca 06 Nov 2005, 07:45
sorry for the respond looks so bad I dont now what hapen wen I write it
it looks aligned this is may first reply ever I just want to give the sensation of being explaining line by line next time I will put the sourse and may comentaries separated |
|||
![]() |
|
estrang 06 Nov 2005, 09:00
NP thnks for the help. I still get a problem though. The overwritten is solved but still have a problem.
Output is wrong: Code: Please Enter a string: Hello World Output: string: ed the string: Hello World And also how come this wont work?? Code: mov ax, [ds:dx-2] or this doesnt work too mov dx, dx -2 i remember trying this before i remember it worked. here is the current source: Code: org 100h start: mov dx, hl_text mov ax, 0900h int 21h input_string_here: mov ax, 0A00h int 21h dispaly_ye_text: add dx, 02h push dx mov dx, ye_text mov ax, 0900h int 21h display_output: pop dx int 21h getch: mov ax, 0700h ;getch() in TC int 21h mov ax, 4C00h int 21h hl_text db 'Please Enter a string: ', 24h ye_text db 0Ah; db 'You entered the string: ', 24h |
|||
![]() |
|
profkid13 06 Nov 2005, 11:27
or this doesnt work too
mov dx, dx -2 this can only work when you use numbers etc like mov dx,5-3 in this case, the precompiler calculates it for you ![]() should be sub dx,2 |
|||
![]() |
|
estrang 06 Nov 2005, 16:06
e.g. i want dx to point 2 spot higher than its current psosition how do i do that??
like dx is currently pointing to address segment::100 and i want it to point to 120 hows that?? |
|||
![]() |
|
estrang 06 Nov 2005, 22:27
In a reference for using interrupts. It says that after inputting a string buffer. the buffer inputted will be located at ds::dx . So after inputting the string will be located in dx, am i right?
But there is 2 bytes the the begginning of the string that i dont need. So i did add dx, 02h. Is the a better way that this that ill make more sense when you look at it?? like mov, dx [ds:dx+2]?? Does any1 know what am i doing wrong with the current code?? I think the seconmd line of output is still overwritting each other. There are probably junks in the output. probably another '\r' that why its overwritting wht i have written. Code: input_string_here: mov ax, 0A00h int 21h dispaly_ye_text: add dx, 02h ;i did this coz my reference says that the first is the size and the second is the bytes read. push dx mov dx, ye_text mov ax, 0900h int 21h |
|||
![]() |
|
Matrix 06 Nov 2005, 23:50
estrang,
you should read the flat assembler documentations, your thread is going back to the beginning, what is addressing. this is not forbidden, but it whould be easier if you read the docs... in this case: dx holds the address of the character, (ds:dx) if you mov dx,5 then ds:5 is the address |
|||
![]() |
|
estrang 07 Nov 2005, 00:12
Ah IC. Ok ill reread it.
|
|||
![]() |
|
daluca 07 Nov 2005, 02:10
mov dx,dx-2 dont work beacouse the assembler needs numbers
dx can hold numbers but it doesnt have any particular value this is one of the diferences betwen C and asm. the mov instruction is not an assignament operator like : dx = dx-2 if you want to dx be dx-2 you have to decrement it twice: dec dx dec dx or substract 2 from it: sub dx,2 mov ax,[ds:dx-2] doesnt work beacouse dx is not ment to be use as an adressing register but you can use bx,si,di,bp instead your message gets still overwritten becouse you are still using the first message as buffer,you should use another buffer |
|||
![]() |
|
estrang 07 Nov 2005, 07:43
Ok got it. Bback i think i really need to reread the manual.
|
|||
![]() |
|
vid 07 Nov 2005, 13:51
daluca: use [code] and [/code] tags around your code to make it readable...
Last edited by vid on 14 Nov 2005, 16:04; edited 1 time in total |
|||
![]() |
|
estrang 08 Nov 2005, 18:35
Ive read the manuals. But still cant figure out why that script is not printing correctly. Can someone tell me wht am i doing wrong with it??
|
|||
![]() |
|
Matrix 09 Nov 2005, 02:42
estrang,
sorry i thought it was a user error at first sight, but now, i say i didn't knew there were so much bugs in dos functions, i knew about some at the read string part, i managed to succeed with hard task, using this dos function as it should work, but something is not right at this function, i did not take tha time to debug the dos function what is wrong, i can recommend writing your own function for reading a string, the error is in dos read string and write string, i personally dont use this function of dos. heres a code i wrote for taking a simple string as input and echo ing it as you whould like to, using bios functions: Code: org 100h mov ax,$3 int 10h ; setmode 80x25 text start: mov si, hl_text ; display hl_text call bwrite input_: mov si, hl_text ; offset to buffer mov cx, 128 ; max call readstring01 ; parameter: cx=buffer size, ds:si = destination buffer, starts at bios xy coordinates call newline mov si, gl_text call bwrite mov si, hl_text call bwrite getch: xor ah,ah ; zero out ah int 16h ; bios wait keypress ret ;exit without dos int 21h bwrite: push ax bx xor bx,bx .core: lodsb ; ds:si is source, 0 terminated string or al,al jnz .go pop bx ax ret .go: mov ah,0Eh int 10h ; display jmp .core bwritechar: push bx cx ; al is input char, written at cursor position mov ah,0Ah xor bx,bx mov cx,1 ; count int 10h ; display pop cx bx ret readstring01: push es; parameter: cx=buffer size, ds:si = destination buffer, starts at bios xy coordinates push ds pop es mov di,si mov [.max],cx call bgetxy mov [startxy],dx .maincore: push si di call breadkey pop di si cmp ax,$1C0D ; enter je .done cmp ax,$0E08 ; backspace jne .addchar call decxy ; decxy, set new xy mov al,' ' call bwritechar call decxy ; decxy, set new xy cmp di,si jbe .not dec di .not: mov byte [di],0 ; truncate string buffer call updatestring ; update string on screen jmp .maincore .addchar: mov cx,di sub cx,si cmp cx,[.max] jae .skip stosb call incxy ; inc x, pointer, set new xy mov byte [di],0 ; truncate string buffer .skip: call updatestring ; update string on screen jmp .maincore .done: pop es ret .max: dw 0 startxy: dw 0 updatestring: pusha ; update string on screen mov dx,[startxy] call bgotoxy call bwrite popa ret decxy: call bgetxy ; sub 1 from xy or dl,dl jnz .ok ; not at x=0 or dh,dh ; y is 0? jz .mod dec dh ; y pos dec mov dl,80 ; x pos end .ok: dec dl ; dec offset in buffer call bgotoxy ; set new xy .mod: ret ; return incxy: call bgetxy ; add 1 to xy cmp dl,79 ; xmax jb .ok cmp dh,24 ; ymax jae .mod inc dh ; y pos inc xor dl,dl ; x pos home .ok: inc dl call bgotoxy ; set new xy .mod: ret breadkey: mov ah,$10 ; biosreadkey returns ax int $16 ret bgotoxy: ; dl=x, dh=y ( 0,0 = upper left ) pusha ; transparency mov ah,2 xor bh,bh int 10h popa ret bgetxy: ; ( 0,0 = upper left ) Return: AX = 0000h (Phoenix BIOS) ; CH = start scan line, CL = end scan line, DH = row (00h is top), DL = column (00h is left) push ax push bx push es push ds push si push di mov ah,3 xor bh,bh int 10h pop di pop si pop ds pop es pop bx pop ax ret newline:mov si, .text_ call bwrite ret .text_: db 0Dh,0Ah,0 gl_text: db 'You entered the string: ',0 hl_text: db 'Please Enter a string: ',0 ; order this so wont be possible to owerwrite the other string ;--------V-1002------------------------------- ;INT 10 - VIDEO - SET CURSOR POSITION ; AH = 02h ; BH = page number ; 0-3 in modes 2&3 ; 0-7 in modes 0&1 ; 0 in graphics modes ; DH = row (00h is top) ; DL = column (00h is left) ;Return: nothing ;SeeAlso: AH=03h,AH=05h,INT 60/DI=030Bh,MEM 0040h:0050h ;--------V-1003------------------------------- ;INT 10 - VIDEO - GET CURSOR POSITION AND SIZE ; AH = 03h ; BH = page number ; 0-3 in modes 2&3 ; 0-7 in modes 0&1 ; 0 in graphics modes ;Return: AX = 0000h (Phoenix BIOS) ; CH = start scan line ; CL = end scan line ; DH = row (00h is top) ; DL = column (00h is left) ;Notes: a separate cursor is maintained for each of up to 8 display pages ; many ROM BIOSes incorrectly return the default size for a color display ; (start 06h, end 07h) when a monochrome display is attached ;SeeAlso: AH=01h,AH=02h,AH=12h/BL=34h,MEM 0040h:0050h,MEM 0040h:0060h ; ;INT 10 - VIDEO - WRITE CHARACTER ONLY AT CURSOR POSITION ; AH = 0Ah ; AL = character to display ; BH = page number (00h to number of pages - 1) (see #00010) ; background color in 256-color graphics modes (ET4000) ; BL = attribute (PCjr, Tandy 1000 only) or color (graphics mode) ; if bit 7 set in <256-color graphics mode, character is XOR'ed ; onto screen ; CX = number of times to write character ;Return: nothing ;Notes: all characters are displayed, including CR, LF, and BS ; replication count in CX may produce an unpredictable result in graphics ; modes if it is greater than the number of positions remaining in the ; current row ;SeeAlso: AH=08h,AH=09h,AH=11h"Tandy 2000",AH=4Bh,INT 17/AH=60h ;SeeAlso: INT 1F"SYSTEM DATA",INT 43"VIDEO DATA",INT 44"VIDEO DATA" feel free to use, modify if you like to btw, come look at the FaQs especially the interrupt list part, where you can find yourself an interrupt list, where you can download your free copy if you dont have one already |
|||
![]() |
|
Remy Vincent 09 Nov 2005, 04:09
estrang wrote: Im very new to asm. Im out of idea what going wrong here... Code: org 100h start: mov dx, hl_text mov ax, 0900h int 21h input_string_here: MOV DX, YE_BUF mov ax, 0A00h int 21h dispaly_ye_text: add dx, 02h push dx mov dx, ye_text mov ax, 0900h int 21h display_output: pop dx int 21h getch: mov ax, 0700h ;getch() in TC int 21h mov ax, 4C00h int 21h hl_text db 'Please Enter a string: ', 24h ye_text dd 0A0Dh; db 'You entered the string: ', 24h YE_BUF db 34,0,'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' _________________ Groups lower your IQ |
|||
![]() |
|
Remy Vincent 09 Nov 2005, 04:12
I have done my own "very funny" version of this program
-Try to enter >>>123456"<<<, it works nearly well... ORG 100h USE16 ;----- Display hello text MOV DX , C_HelloText MOV AH , 09h ; INT 21h , Function 09h , Display String...$ INT 21h ;----- Input string here: MOV DX , C_InputBuffer MOV AH , 0Ah INT 21h ; DX contains the Offset of the entered string ;----- Display yeah text MOV DX , C_YeahText MOV AH , 09h ; INT 21h , Function 09h , Display String...$ INT 21h ;----- TERMINATE PROGRAM INT 20h ;=============== Data C_HelloText DB "Please enter a string: " , "$" C_YeahText DB 13 , 10 , "You entered the string: " C_InputBuffer DB 34 , 0 , "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" ;--123456789012345678901234567890123456789012345-- |
|||
![]() |
|
Remy Vincent 09 Nov 2005, 04:22
With this user input, my program works too!!!:
- <<<14teenCharSong>>> |
|||
![]() |
|
Remy Vincent 09 Nov 2005, 05:01
If you enter "country names" as user input, the added small symbol often matches with a "could be usual" sentence about the country...
I tried: >>>France>>> : France is serious country! >>>United Kingdom<<< : Many good music from there! <<<USA>>> : some clothes with "I love USA"! _________________ Groups lower your IQ |
|||
![]() |
|
Remy Vincent 09 Nov 2005, 05:12
<><Austrialia><> : This country is far away
_________________ Groups lower your IQ Last edited by Remy Vincent on 09 Nov 2005, 05:28; edited 1 time in total |
|||||||||||
![]() |
|
Remy Vincent 09 Nov 2005, 05:22
![]() ![]() ![]() ![]() _________________ Groups lower your IQ |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.