0

im a begginner at os developing, so i started devloping in real mode 16 bits. assuming i decalre 4 bytes one after another by the following opreations:

temp1 db 0 
temp2 db 0 
temp3 db 0 
temp4 db 0 

I want to fill all of them with input to the user without addressing every single one of them by name. i tried storying the first temp1's memory address in bx, then check if its 0(default vaule), if its not fill it with input and increase bx then proceed this until enter was entered , this is how i tried :

mov bx, temp1
push bx
call read_key123

read_key123: 
    mov ax, 0
    mov ah, 10h         
    int 16h
    cmp al,13d
    jz enter_pressed 
    mov ah,0Eh
    int 10h
    call fill_temp
    jmp read_key

fill_temp:
    pop bx
    cmp byte [bx],0
    jne fill_temps_check
    mov [bx],al
    inc bx
    push bx
    call return_main
fill_temps_check:
    cmp bx, temp4
    je wrong_input
        ret
return_main:
    ret
temp1 db 0 
temp2 db 0 
temp3 db 0 
temp4 db 0 

assume wrong_input is a label to print a message. thank you in advance!

Jester
  • 56,577
  • 4
  • 81
  • 125
Circel
  • 1
  • What problem(s) are you having with this code? – Scott Hunter Jan 22 '16 at 21:33
  • 1
    You pop'ed `bx` when the last thing you pushed was the return address (by calling the pop), while that is sometimes a legitimate thing to do it does not look like you intended to do it. calling a ret is also weird. – harold Jan 22 '16 at 21:33
  • the problem im having is that it does not seem to work, infact i actually can only enter 1 character (and get it displayed) before the program stop respoding(equal to jmp $). – Circel Jan 22 '16 at 21:37
  • also I don't understand the return address Ur talking about, by poping i move the upper stack to bx, which i pushed earlier. – Circel Jan 22 '16 at 21:39
  • 4
    The instruction `call fill_temp` is dynamically immediately followed by a pop. That pop therefore pops the address just pushed by the call, and the `cmp [bx], 0` is therefore comparing the opcode byte of `jmp read_key` to zero. – harold Jan 22 '16 at 22:02
  • I think you want `jmp` in a lot of the places you used `call`. – Peter Cordes Jan 23 '16 at 03:00

0 Answers0