d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Assembly Language Menu System
Add Reply New Topic New Poll
Member
Posts: 9,525
Joined: Nov 5 2005
Gold: 1,338.00
Mar 9 2014 11:48am
Alright so, basically I have to create a program in assembly that will call a menu procedure to display a two line menu:

"c" - to continue
"x" - to quit

Then it will get one of those keys from the user, ignoring any others. If it's x, then it'll quit, otherwise if it's c, then I call a third procedure named display. That procedure just prints out the number 10 and returns.

Here's what I have so far:

Quote (Makefile)
TARGET = menu

AFILES = main.asm\
  menu.asm\
  display.asm

#Don’t modify below this line:
include /usr/local/include/project.mak


Quote (main.asm:)
%include “/usr/local/include/asm_io.inc

section  .text

global asm_main
extern menu

asm_main:

call fib_menu

ret


Quote (menu.asm:)
global menu
extern display

section  .data

menuInfo  db  "c - to continue",10
                      "x - to quit”,10,0


menu:

push rbp
mov  rbp, rsp

mov  rdi, menuInfo
call  print_string

mov  R8, 10
push R8
call display
pop R8

mov RDI, R9
call print_string

mov  rsp,  rbp
pop  rbp

ret


Quote (display.asm:)
global display

display:

push rbp
mov  rbp, rsp

;;;DISPLAY CODE HERE
mov R9, ;SOMETHING

mov  rsp,  rbp
pop  rbp

ret


I think I have the general format right, I just have no idea how I would keep looping and displaying 10 until the user presses X.

Any thoughts/ideas?

This post was edited by Rejection on Mar 9 2014 11:56am
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 9 2014 12:11pm
You should be commenting every line of code in assembler in a higher level language or psdudo code, also include your other files. From what you posted you have 0 logic flow to determine what a user attempted to input, or rather no real IO at all besides printing something (does this function also obtain user input?).

The instructions, after you sort out the rats nest of other problems you have, that you are looking for are the cmp and jmp/je/jle/jl/jg/jge instructions which will house your logic flow. You will want to compare the first character of user input to the ascii equivalent of your menu option.

example:

Code
#if %rax holds your user input

mov (%rax, 2, 0), %al

#jump if our first byte of input is equal to 'c'
cmpb $99, %al
je C_PRESSED

#jump if our first byte of input is equal to 'x'
cmpb $120, %al
je X_PRESSED

#mandatory jump if we find no suitable conditions
jmp WRONG_INPUT


If it is easier for you, link against ld-linux.so.2 / libc.so and use printf/scanf/fgets and the like for your IO. Will save you time from writing your own functions.

example:

Code
as yourfile.s -o yourfile.o
ld -dynamic-linker /lib/ld-linux.so.2 -o yourfile yourfile.o -lc


If you're trying to learn this on your own, I suggest reading ProgrammingGroundUp-1-0-lettersize.pdf which can be found for free on cs.princeton.edu with google. It's old and 32bit using at&t syntax, but it will give you a better grasp on assembler. If this is for school I suggest you brush up on what you missed. They must of taught you about the compare statements and all the hidden flags that trigger during specific instructions.

This post was edited by AbDuCt on Mar 9 2014 12:29pm
Member
Posts: 9,525
Joined: Nov 5 2005
Gold: 1,338.00
Mar 10 2014 09:42am
WOW! Thank you for that reference AbDuCt! That's incredible. I've read the first 50 pages, and I love the way this guy writes and explains things. Yeah I probably wont be here for at least a week, just reading this shiz.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll