2

I have the following code.

.data
msg         db 10, 13, "this is a string $"
bufferSize  db 21  ; 20 char + RETURN
inputLength db 0   ; number of read characters
buffer      db 21 DUP(0) ; actual buffer

.code

main proc
    mov ax, @data
    mov ds, ax
    lea dx, msg
    mov ah, 09h ;output
    int 21h

    mov dx, offset bufferSize ; load our pointer to the beginning of the structure
    mov ah, 0Ah ; GetLine function
    int 21h

    xor dx, dx
    lea dx, buffer
    mov ah, 06h ;output
    int 21h

    mov ah,0
    int 21h

endp
end main

The code should prompt for a name, and then display it. It correctly prompts, but it doesn't display the result.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • 1
    `int 21h/ah=06h` reads a single character. Perhaps you meant to use `int 21h/ah=0ah`. Also, `int 21h/ah=09h` prints _strings_, so you can't use it to print a single character the way you're trying to do at the end of your program. – Michael Jan 08 '18 at 16:01
  • yeah i used 0ah and it worked but where does it store the input after taking it? and what do you mean if i take input cant i print it with 21h/09h? what can i use to print it than? – Just a Salad Knight Jan 08 '18 at 16:21
  • _"but where does it store the input after taking it"_ Where you [told the interrupt function to store it](http://spike.scu.edu.au/~barry/interrupts.html#ah0a). _"what do you mean if i take input cant i print it with 21h/09h"_ It looks like you're trying to print a single character by placing the character in `dl` and then using `int 21h/ah=09h`. That isn't going to work since `int 21h/ah=09h` prints `$`-terminated strings. Look up a reference on the `int 21h` functions to see which functions are available to you. – Michael Jan 08 '18 at 16:29
  • i updated it tell me where the problem is if you can :) – Just a Salad Knight Jan 08 '18 at 16:38
  • you reserve space in .data, but give the DOS `.code:BufferSize` address, which is different segment if you have EXE file (`cs` == `ds` only in COM files). After your first output is correct, that's the correct `ds` also for your buffer, so there is no need to do `mov ax,cs` `mov ds,ax`, that's settings `ds` to point to `.code` segment. – Ped7g Jan 08 '18 at 16:41
  • updated it again.... sorry for bothering you but im learning assembly completly alone :) – Just a Salad Knight Jan 08 '18 at 16:47
  • `mov ah, 06h ;output` ... vs `lea dx, buffer` - that's not how it works, the `dl` should contain character to output. The link about from Michael contains all services described. Are you learning alone from some resource, or are you guessing alone? The second will not work well with assembly, it's not following common sense, like high level languages. Read something about computer architecture, few particular tutorials, read some other examples, maybe search SO and codereview sites to see which problems other are solving, etc... You may event want to surf through my answers looking for source. – Ped7g Jan 08 '18 at 17:34

4 Answers4

1

You'll find everything you need and more if you study example1 in How buffered input works

The code should prompt for a name, and then display it. It correctly prompts, but it doesn't display the result.

The example in the linked post does exactly that.

  1. It prints a prompt.
  2. It inputs using function 0Ah.
  3. It prints the result.
Fifoernik
  • 9,779
  • 1
  • 21
  • 27
0
.MODEL SMALL;Code model set to small
.STACK 100H ;Stack memory 100H size
.CODE       ;Code starts from here

START:      ;Mark start of code segment

INPUT:      ;Mark input of code segment
MOV AH, 1   ;AH=1,Single key input
INT 21H     ;Input in AL
MOV BL, AL  ;BL=AL, Input in BL

OUTPUT:     ;Mark output of code segment
MOV AH, 2   ;AH=2,Single key output 
MOV DL, BL  ;DL=BL, Display the input
INT 21H     ;Print DL


Exit:       ;Mark exit of code segment
MOV AH, 4CH ;4CH = DOS exit fuction. Handover the control to OS and exit program
INT 21H     ;Invoke the instruction for interrupt where there function needs to be executed
-1
.model small
.stack 100h 
.data
msg         db 10, 13, "this is a string $"
bufferSize  db 21  ; 20 char + RETURN
inputLength db 0   ; number of read characters
buffer      db 21 DUP("$") ; actual buffer

.code
main proc

mov ax, @data
mov ds, ax
lea dx, msg
mov ah, 09h ;output
int 21h

mov dx, offset bufferSize ; load our pointer to the beginning of the structure
mov ah, 10 ; GetLine function
int 21h

mov ax, @data 
mov ds , ax 
lea dx, buffer
mov ah, 09 ;output
int 21h

endp
end main    
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Before the bad edit that replaced this with someone else's answer, this was a copy/paste of the question with a couple minor changes; some of them useless (an extra `mov ax, @data` / `mov ds, ax`), and no explanation of which change actually fixed the bug (the final `int 21h` having the wrong call number, 06 read char instead of 09 write string) – Peter Cordes Mar 30 '22 at 20:51
  • (BTW, I flagged the bad edit for a moderator to look at; IIRC it's best to leave the wrongly-approved edit as the most recent, so moderator tools can more easily handle the necessary review bans for those who approved it, or something? Anyway, that's why I didn't roll it back myself.) – Peter Cordes Mar 30 '22 at 20:54
-1
.model tiny
.stack 100h
.code
main proc
    mov ah,1
    int 21h
    mov bl,al 
    
    mov ah,1
    int 21h
    mov bh,al
    
    mov ah,2
    mov dl,bl
    int 21h   
    
    
    mov ah,2
    mov dl,bh
    int 21h
              
              
end main
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 4
    Code dumps with no explanation are not very useful to people trying to learn how the pieces fit together to make a working program. This appears to read exactly 2 bytes (and then write them back out again in order), regardless of how many the user wants to type. – Peter Cordes Mar 23 '22 at 05:13
  • Your recent edit that added some text to go with this was made on someone else's answer, replacing it with a broken-formatting version of yours. That's since been [fixed by a moderator](https://stackoverflow.com/posts/53970166/revisions). If you still want to add explanatory text, [edit] your own answer – Peter Cordes Apr 04 '22 at 20:41