Hey guys i just joined, I am sure this is a dumb question, but i been googling for the past week and cant seem to find a simple answer. I been trying to learn asm and I am trying to make a menu system. So like you type 1 and it jumps to that, you type 2 it jumps to that and so on. I cant seem to find out how to get user input though. Sorry if the answer is already on the forums I cant seem to find it.

Thanks for you help.

What OS are you using?

If it is x86 google "dos interrupt 21h".
If you are on a MIPS processor you'll need to google "mips syscall".

Hope this helps.

Ok thank you, I usually boot from a cd when I do programming. So i use backtrack which is Linux.

Also what assembler because some assemblers have macros that do all (or most) of the grunt work of calling system functions.

Ok thank you, I usually boot from a cd when I do programming. So i use backtrack which is Linux.

You mean you actually boot linux from a CD :-O You must be awfully patient to wait all that time for your computer to boot up.

Lol, well i have windows as my default and i only use my 1 hard drive which is 36gigs but its a raptor so its 10000 rpms which is nice. I have another one but something happened and its not working properly. So i cant grub boot. But i use NASM as my compiler.

>>But i use NASM as my compiler

Its not a compiler, but an assembler. :)

Well yea, So I try to do like

mov ah,01h
int 16h

Shouldn't that let the user in put whatever he/she wants?

you need a good explaination of those interrupt functions. Here is just one of them you can find. Function 1, which you posted, only tests to see if a key has been pressed. You have to call other functions to actually get the value, such as function 10. But it too only returns the value of ONE key, so you have to create a loop and keep calling those two functions until function 1 says no-more-keys.

what you do with those keys is up to you -- normally you will want to put then into a buffer so that they can be easily used whenever you want.

Ok thank you, just curious though with that they give you how to run the different things. Like for example....
INT 21,2B - Set Date
EXAMPLE
would i do

section .data

global _start

_start:

AH = 2B
CX = 2007
DH = 10
DL = 22
int 21

>>would i do
Not quite. you have to use valid assembly language syntax.

O yea iam sorry I meant to do commas instead on equal signs. I just didnt change it over when I copyed it.

Well yea, So I try to do like

mov ah,01h
int 16h

Shouldn't that let the user in put whatever he/she wants?

That is a DOS system call... it will only work on Linux if you are running a DOS emulator. Nothing wrong with that, but since you are using Linux, why not run your programs natively? Some Linux ASM resources are here:

http://asm.sourceforge.net/resources.html#docs
http://members.save-net.com/jko@save-net.com/asm/

A "Hello, World!" for Linux looks like this:

; nasm -f elf hello.asm
; ld -o hello hello.o
global _start

section .data
	hello	db	"Hello, World!", 10
	length	equ	$-hello

section .text

_start:
	mov eax, 4		; write to file
	mov ebx, 1		; STDOUT handle
	mov ecx, hello	; our message
	mov edx, length	; size of message
	int 80h			; execute the syscall

	xor ebx, ebx		; send 0 as 'exit code'
	mov eax, 1		; terminate process
	int 80h			; execute the syscall

Nathan.
http://del.icio.us/Evenbit/Linux

Ok thank you. Actually though i found a windows assembly I like a lot. Its called emu8086 www.emu8086.com so I been using that and the only thing I am having trouble with now is my comparing/testing instructions to jump around.

name "menu"
data segment
    pkey db "press any key...$"



s db 'RACECAR'
s_size = $ - m1
  db 0Dh,0Ah,'$'

msg1 db " This is a palindrome.$"
msg2 db " This is not a palindrome.$"

num db "Enter any number from -32768 to 65535.$, or zero to stop"
bin db "Binary form is $"
buffer db 7,?, 5 dub <0>, 0, 0
binary dw ?



ends

stack segment
    dw   128  dup(0)
ends

code segment
menu:
    mov ax, data
    mov ds, ax
    mov es, ax
clear_screen
   print 7,7,0000_1010b,"Press 1 for Hello World."
   print 7,8,0000_1010b,"Press 2 for palindrome."
   print 7,9,0000_1010b,"Press 3 to see the position of your mouse."
   print 7,10,0000_1010b,"Press 4 to exit."
   print 7,11,000_1010b,"Enter the number: "
mov ax,1
int 33h
  
  mov ah,0ah
  int 21h

    cmp ah,1
    je World
    cmp ah,2
    je palindrome
    cmp ah,3
    je mouse
    cmp ah,4
    je stop
    

World:
mov ax,3
int 10h

mov ax,1003h
mov bx,0
int 10h

mov ax,0b800h
mov ds,ax

mov [02h], 'H'
mov [04h], 'e'
mov [06h], 'l'
mov [08h], 'l'
mov [0ah], 'o'
mov [0ch], ','
mov [0eh], 'W' 
mov [10h], 'o'
mov [12h], 'r'
mov [14h], 'l'
mov [16h], 'd'
mov [18h], '!'

mov cx,12
mov di, 03h

c:

mov [di], 00001010b
add di, 2
loop c

mov ah,0
int 16h

jmp menu

Palindrome:
mov ah, 9
mov dx, offset s
int 21h

lea di,s
mov si,di
add si, s_size
dec si

mov cx, s_size
cmp cx, 1
je is_palindrome

shr cx, 1

next_char:

mov al, [di]
mov bl, [si]
mov al, bl
jne not_palindrome
inc di
dec si
loop next_char

is_palindrome:

mov ah, 9
mov dx, offset msg1
int 21h
jmp stop

not_palindrome:

mov ah, 9
mov dx, offset msg1
int 21h
jmp menu



mouse:

print macro x, y, attrib, sdat
LOCAL   s_dcl, skip_dcl, s_dcl_end
    pusha
    mov dx, cs
    mov es, dx
    mov ah, 13h
    mov al, 1
    mov bh, 0
    mov bl, attrib
    mov cx, offset s_dcl_end - offset s_dcl
    mov dl, x
    mov dh, y
    mov bp, offset s_dcl
    int 10h
    popa
    jmp skip_dcl
    s_dcl DB sdat
    s_dcl_end DB 0
    skip_dcl:    
endm

clear_screen macro
    pusha
    mov ax, 0600h
    mov bh, 0000_1111b
    mov cx, 0
    mov dh, 24
    mov dl, 79
    int 10h
    popa
endm

print_space macro num
    pusha
    mov ah, 9
    mov al, ' '
    mov bl, 0000_1111b
    mov cx, num
    int 10h
    popa
endm


jmp mo

curX dw 0
curY dw 0
curB dw 0


mo:
mov ax, 1003h ; disable blinking.  
mov bx, 0        
int 10h

; hide text cursor:
mov ch, 32
mov ah, 1
int 10h


; reset mouse and get its status:
mov ax, 0
int 33h
cmp ax, 0
jne ok
print 1,1,0010_1111b, " mouse not found :-( "
jmp stop

ok:
clear_screen

print 7,7,0010_1011b," note: in the emulator you may need to press and hold mouse buttons "
print 7,8,0010_1011b," because mouse interrupts are not processed in real time.           "
print 7,9,0010_1011b," for a real test, click external->run from the menu.                "
print 10,11,0010_1111b," click/hold both buttons to exit... "


mov ax, 1
int 33h

check_mouse_buttons:
mov ax, 3
int 33h
cmp bx, 3  
je  hide
cmp cx, curX
jne print_xy
cmp dx, curY
jne print_xy
cmp bx, curB
jne print_buttons


print_xy:
print 0,0,0000_1111b,"x="
mov ax, cx
call print_ax
print_space 4
print 0,1,0000_1111b,"y="
mov ax, dx
call print_ax
print_space 4
mov curX, cx
mov curY, dx
jmp check_mouse_buttons

print_buttons:
print 0,2,0000_1111b,"btn="
mov ax, bx
call print_ax
print_space 4
mov curB, bx
jmp check_mouse_buttons



hide:
mov ax, 2 
int 33h

clear_screen

print 1,1,1010_0000b," hardware must be free!      free the mice! "

stop:

mov ah, 1
mov ch, 0
mov cl, 8
int 10h

print 4,7,0000_1010b," press any key.... "
mov ah, 0
int 16h

ret


print_ax proc
cmp ax, 0
jne print_ax_r
    push ax
    mov al, '0'
    mov ah, 0eh
    int 10h
    pop ax
    ret 
print_ax_r:
    pusha
    mov dx, 0
    cmp ax, 0
    je pn_done
    mov bx, 10
    div bx    
    call print_ax_r
    mov ax, dx
    add al, 30h
    mov ah, 0eh
    int 10h    
    jmp pn_done
pn_done:
    popa  
    ret  
endp


end menu

what do you think is wroung with it?

I had this problem at one point too. Try this out.

mov ah,08 ;Keyboard input function
int 21h ;Call DOS

cmp al,HEX_VALUE_OF_KEY
je near WHERE_TO_JUMP

using "near" for your jump removed the chance of getting "Short jump out of range"

This is windows, not sure on linux.. Never hurts to try though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.