How can I create a simple menu?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1342 Views - Last Post: 13 December 2013 - 10:38 PM

#1 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

How can I create a simple menu?

Posted 01 December 2013 - 07:36 AM

Hell everyone. I use emu8086 and I want to create a simple menu. Here's a picture of what I have in mind:


I know how to write the codes for making a file (create file), showing some text (about), and finish the program (exit), what I need is a code for making a simple menu, so when someone presses Create File for example, the program could do that, or when someone presses About, we could see the text information.

Many thanks in advance

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: How can I create a simple menu?

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3733
  • View blog
  • Posts: 13,049
  • Joined: 12-December 12

Re: How can I create a simple menu?

Posted 01 December 2013 - 10:50 AM

Buttons don't exist in isolation, they exist within a GUI - a Windows Application (aka a Windows Form).

Does emu8086 have a GUI editor or builder? I don't know and, until you receive another response, you might search. (It is only an emulator after all, so it may not be able to cope with, or assist you in building, a GUI.)
Was This Post Helpful? 1
  • +
  • -

#3 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: How can I create a simple menu?

Posted 01 December 2013 - 01:47 PM

If you are writing this for Windows, the best way to make menus is with the Windows API.
Was This Post Helpful? 1
  • +
  • -

#4 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 04 December 2013 - 08:58 PM

I've found this piece of code:

org 100h        

start:  mov     dx, msg1  
        mov     ah, 09h 
        int     21h     
        
getnum:        
        mov     ah, 7 
        int     21h        
        cmp     al, '1' 
        jl      getnum   
        cmp     al, '8'
        jg      getnum 
        mov     ah, 2   
        mov     dl, al
        int     21h    
             
        mov     [msg2+9], al
        mov     dx, msg2  
        mov     ah, 09h 
        int     21h             
                
ret

msg2: 
        db      0Dh,0Ah,0Dh,0Ah,"Item ? Selected$" 
   
msg1:   db      "Please select an item:",0Dh,0Ah,0Dh,0Ah,09h
        db      "1- Item1",0Dh,0Ah,09h
        db      "2- Item2",0Dh,0Ah,09h      
        db      "3- Item3",0Dh,0Ah,09h
        db      "4- Item4",0Dh,0Ah,09h
        db      "5- Item5",0Dh,0Ah,09h
        db      "6- Item6",0Dh,0Ah,09h
        db      "7- Item7",0Dh,0Ah,09h
        db      "8- Item8",0Dh,0Ah,0Dh,0Ah
        db      "Enter item number: " 
        db      '$'



Can I import the other codes into this? how can I add this code into above, so when I press "1-Item1" it could make a txt file:

org  100h
jmp new
dir1 db "c:\test1", 0
file1 db "test.txt", 0
handle dw ?
text db "test"
text_size = $ - offset text
new:
mov ah, 3ch
mov dx, offset file1
int 21h
mov handle, ax
mov ah, 40h
mov bx, handle
mov dx, offset text
mov cx, text_size
int 21h
mov dx, offset dir1
int 21h           
ret


Thanks
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: How can I create a simple menu?

Posted 05 December 2013 - 06:52 AM

View PostHowtoX, on 04 December 2013 - 10:58 PM, said:

I've found this piece of code:
Can I import the other codes into this?

Those are 16 bit registers. Without seeing your code, I can only say maybe. It depends on if your code is also using 16 bit registers.

It's been a while since I've coded in assembly. Far too long to be honest. But I seem to recall that you can't mix 16 & 32 bit registers. Maybe someone can clarify, as I don't want to tell you for sure & give you wrong information.
Was This Post Helpful? 1
  • +
  • -

#6 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,302
  • Joined: 28-March 11

Re: How can I create a simple menu?

Posted 05 December 2013 - 07:51 PM

Quote

how can I add this code into above, so when I press "1-Item1" it could make a txt file:

C'mon, no effort? We are only using a handful of simple instructions here, nothing fancy. You get input, check to see if it is valid, then branch off to perform some function depending on the menu choice, once that is done, go back and repeat menu for next choice or quit. No high level abstractions. Get a piece of paper and a pencil, and write down what you want done and the steps to do it:

1. display menu
2. get input
3. validate input
4. perform some code depending on menu choice:
  • If al = 1 then create file
  • If al = 2 then show about
  • If al = 3 then Feed the cat
  • If al = 4 quit


5. repeat 1 - 4 until quit chosen

Ok, you have 1 - 3 done, now after you get a valid menu choice, compare al and depending on the value, jump to or call a procedure to do something.

This:
getnum:        
        mov     ah, 7
        int     21h        
        
        cmp     al, '1' 
        jl      getnum   
        cmp     al, '8'
        jg      getnum 
        
        mov     ah, 2   
        mov     dl, al
        int     21h    


Can be rewritten as:
getnum:        
        mov     ah, 1 
        int     21h        
        
        cmp     al, '1' 
        jl      getnum   
        cmp     al, '8'
        jg      getnum 

See the difference? We use the interupt - int 21H/AL=1 - Read character from Standard Input WITH echo, now you don't need that unneeded call to int 21H/AL=2 after your menu validation.

Here is a sample:
.model small
.stack 100h

.data
msg1    db      10, 13, 10, 13, "Please select an item:",0Dh,0Ah,0Dh,0Ah,09h
        db      "1- Create File",0Dh,0Ah,09h
        db      "2- About",0Dh,0Ah,09h      
        db      "3- Exit",0Dh,0Ah,09h
        db      "Enter item number: " 
        db      '$'   
        
About   db      10, 13, 10, 13, "I am some text about the program!$"

handle  dw  ?
file1   db  "test.txt", 0
text    db  "test text",0
text_size equ $ - text
  
.code
main proc 
    mov   ax,@data
    mov   ds,ax

ShowMenu:       
    lea     dx, msg1  
    mov     ah, 09h 
    int     21h     
        
getnum:        
    mov     ah, 1 
    int     21h        
    
    cmp     al, '1' 
    jl      ShowMenu   
    cmp     al, '3'
    jg      ShowMenu 
        
    cmp     al, "1"
    je      CreateFile
    cmp     al, "2"
    je      ShowAbout
    cmp     al, "3"
    jmp     Quit
;    cmp     al, "4"
;    jmp     CodeForMenu4
;    etc...
        
Quit: 
   mov   ah,4ch
   int   21h   

Showabout:       
    lea     dx, About  
    mov     ah, 09h 
    int     21h    
    jmp     ShowMenu
    
CreateFile:
    ; open file
    mov     ah, 3ch
    mov     dx, offset file1
    mov     cl, 1
    int     21h
    mov     handle, ax
    
    ; write to file
    mov     ah, 40h
    mov     bx, handle
    mov     dx, offset text
    mov     cx, text_size
    int     21h
    
    ; close handle, data isn't written until handle closed.
    mov     ah, 3eh
    mov     bx, handle
    int     21H         
    
    jmp     ShowMenu                
main endp
end main


Was This Post Helpful? 1
  • +
  • -

#7 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 08 December 2013 - 07:41 AM

Thank you very much for the great information folks. I'm studying the codes and methods. I'll post the final result soon as I'm finished. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#8 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 08 December 2013 - 11:40 PM

Hello again. Thanks to you the program is now working perfectly fine. I can "Create a File", read the "About" section and end it with "Exit". Now I was trying to import another code into the program. This code could read a file and it works stand alone:

org 100h 
mov dx, offset file 
mov al,0
mov ah,3dh
int 21h 
jc terminate 
mov bx,ax
mov cx,1 
print:
lea dx, BUF
mov ah,3fh 
int 21h
CMP AX, 0 
JZ terminate 
mov al, BUF 
mov ah,0eh 
int 10h
jmp print 
terminate:
mov ah, 0 
int 16h
ret
file db "c:\finaltest.txt", 0
BUF db ?
END


And this is a screenshot of the above program:

Posted Image

But what I want to do is to import those codes into the main [menu] program. I tried, but nothing happens when I press 4. The menu just gets reloaded and nothing happens and it can't read the file:

.model small
.stack 100h

.data
msg1    db      10, 13, 10, 13, "Please select an item:",0Dh,0Ah,0Dh,0Ah,09h
        db      "1- Create File",0Dh,0Ah,09h
        db      "2- About",0Dh,0Ah,09h      
        db      "3- Exit",0Dh,0Ah,09h     
        db      "4- Open File",0dh,0ah,09h
        db      "Enter item number: " 
        db      '$'   
        
About   db      10, 13, 10, 13, "Blank Text About the Program$"

handle  dw  ?
file1   db  "c:\finaltest.txt", 0
text    db  "This Message Contains Absolutely Nothing!",0
text_size equ $ - text
  
.code
main proc 
    mov   ax,@data
    mov   ds,ax

ShowMenu:       
    lea     dx, msg1  
    mov     ah, 09h 
    int     21h     
        
getnum:        
    mov     ah, 1 
    int     21h        
    
    cmp     al, '1' 
    jl      ShowMenu   
    cmp     al, '3'
    jg      ShowMenu 
        
    cmp     al, "1"
    je      CreateFile
    cmp     al, "2"
    je      ShowAbout
    cmp     al, "3"
    jmp     Quit          
    cmp     al, "4"
    jmp     OpenFile
        
Quit: 
   mov   ah,4ch
   int   21h   

Showabout:       
    lea     dx, About  
    mov     ah, 09h 
    int     21h    
    jmp     ShowMenu
    
CreateFile:
jmp new
text_size = $ - offset text
new:
mov ah, 3ch
mov dx, offset file1
int 21h
mov handle, ax
mov ah, 40h
mov bx, handle
mov dx, offset text
mov cx, text_size
int 21h
int 21h           
ret
              
OpenFile:    
jmp print
mov dx, offset file 
mov al,0 
mov ah,3dh
int 21h 
jc terminate 
mov bx,ax 
mov cx,1
print:
lea dx, BUF
mov ah,3fh
int 21h
CMP AX, 0 
JZ terminate 
mov al, BUF 
mov ah,0eh 
int 10h
jmp print
terminate:
mov ah, 0 
int 16h
ret
file db "c:\finaltest.txt", 0
BUF db ?
END            

    jmp     ShowMenu                
main endp
end main


These were the new codes I put into three sections of the main program (for having a "OPENFILE" item):

db "4- Open File",0dh,0ah,09h

cmp al, "4"
jmp OpenFile

OpenFile:
jmp print
mov dx, offset file
mov al,0
mov ah,3dh
int 21h
jc terminate
mov bx,ax
mov cx,1
print:
lea dx, BUF
mov ah,3fh
int 21h
CMP AX, 0
JZ terminate
mov al, BUF
mov ah,0eh
int 10h
jmp print
terminate:
mov ah, 0
int 16h
ret
file db "c:\finaltest.txt", 0
BUF db ?
END

Posted Image

How can I make that work? What I'm trying to have is this: When I press "4", the program reads the selected txt file that I have created before (with pressing "1").

Many many thanks in Advance
Was This Post Helpful? 0
  • +
  • -

#9 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,302
  • Joined: 28-March 11

Re: How can I create a simple menu?

Posted 09 December 2013 - 06:46 PM

You seem to be copy and pasting code and have no clue as to what it does....

What does this do????

034 cmp al, '1'
035 jl ShowMenu
036 cmp al, '3'
037 jg ShowMenu

What would you change to allow for a fourth, fifth, or sixth etc... menu item???
Was This Post Helpful? 1
  • +
  • -

#10 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 10 December 2013 - 09:45 AM

Can you please help me with the right one? I know about cmp, but I'm not familiar with jl and jg. Thanks
Was This Post Helpful? 0
  • +
  • -

#11 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,302
  • Joined: 28-March 11

Re: How can I create a simple menu?

Posted 10 December 2013 - 09:30 PM

You have all this code and have no idea how it works or what it does? You don't want to put in any effort? Why not just look up JL and JG for documentation???

You have this code:
ShowMenu:       
    lea     dx, msg1  
    mov     ah, 09h 
    int     21h     
        
getnum:        
    mov     ah, 1 
    int     21h        
    
    cmp     al, '1' 
    jl      ShowMenu   
    cmp     al, '3'
    jg      ShowMenu 


You get user input and check to see if it is a valid menu choice, if it is not, go back and show the menu again.

cmp al, "1"
jl  ShowMenu

If al is less than 1 (0) then jmp to ShowMenu. JL = Jump if Less

    cmp     al, '3'
    jg      ShowMenu 

If al is greater than "3" (4, 5, 6, etc...) then jmp to ShowMenu. JG = Jump if Greater

Otherwise if al = 1, 2, or 3, continue on to the menu choice. Now after that being said... what would you change here:

getnum:        
    mov     ah, 1 
    int     21h        
    
    cmp     al, '1' 
    jl      ShowMenu   
    cmp     al, '3'
    jg      ShowMenu 


To allow a fourth or fifth menu choice?
Was This Post Helpful? 1
  • +
  • -

#12 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 11 December 2013 - 05:02 AM

Thank you very much for information. So basically If I change:

getnum:        
cmp     al, '3'
jg      ShowMenu 




to:

cmp     al, '4'
jg      ShowMenu 


I must be able to press "4" and have the "Open File" function work. But when I do that, the program just halts and nothing happens. As if I've pressed the "exit" function. I think the problem is the way that I call "4"?

ShowMenu:       
    lea     dx, msg1  
    mov     ah, 09h 
    int     21h     
        
getnum:        
    mov     ah, 1 
    int     21h        
    
    cmp     al, '1' 
    jl      ShowMenu   
    cmp     al, '4'
    jg      ShowMenu 
        
    cmp     al, "1"
    je      CreateFile
    cmp     al, "2"
    je      ShowAbout
    cmp     al, "3"
    jmp     Quit          
    cmp     al, "4"
    je    OpenFile



This part exactly:
    cmp     al, "4"
    je    OpenFile


Is it possible to call "4" with je?
Thanks again

This post has been edited by HowtoX: 11 December 2013 - 05:05 AM

Was This Post Helpful? 0
  • +
  • -

#13 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 12 December 2013 - 12:50 PM

Can you please help me? I really appreciate it.
Was This Post Helpful? 0
  • +
  • -

#14 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,302
  • Joined: 28-March 11

Re: How can I create a simple menu?

Posted 12 December 2013 - 08:02 PM

I did not respond in order to give you time to look over your code and try an figure it out.

Quote

I must be able to press "4" and have the "Open File" function work. But when I do that, the program just halts and nothing happens. As if I've pressed the "exit" function. I think the problem is the way that I call "4"?


Look at your code line by line and tell me why you never reach cmp al, "4"

    cmp     al, "1"
    je      CreateFile
    cmp     al, "2"
    je      ShowAbout
    cmp     al, "3"
    jmp     Quit          
    cmp     al, "4"
    je    OpenFile

Was This Post Helpful? 1
  • +
  • -

#15 HowtoX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-October 13

Re: How can I create a simple menu?

Posted 12 December 2013 - 09:13 PM

Quote

Look at your code line by line and tell me why you never reach cmp al, "4"


I thought maybe it's because of using "ret" and "je" at the same time for "OpenFile" . But when I remove that part, it still doesn't work. I really don't know how to reach/call "4".

This post has been edited by HowtoX: 12 December 2013 - 09:15 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2