Author Topic: Help with basic assemly language program  (Read 8109 times)

Offline kingpoop

  • Jr. Member
  • *
  • Posts: 2
Help with basic assemly language program
« on: July 01, 2021, 04:51:02 AM »
Can anyone help me see what i am doing wrong?

I basically am trying to ask y/n questions to add ingredients for ordering a hamburger.

The code asks the first question then runs through the loop until the end. 

I need to ask each question and enter y or n

thanks,


%include "/usr/local/share/csc314/asm_io.inc"

;10 newline \n
;32 space
;0  \0 null

segment .data
    welcome       db  "Welcome to Burger Shack!",10,"Please choose your toppings: answer y for Yes, n for No",10,0
    lettuceprompt db  "Lettuce?    :",0
    cheeseprompt  db  "Cheese?     :",0
    tomatoeprompt db  "Tomatoe?    :",0
    onionprompt   db  "Onion?      :",0
    pickleprompt  db  "Pickle?     :",0
    ketchupprompt db  "Ketchup?    :",0
    mayoprompt    db  "Mayonnaise? :",0
    mustardprompt db  "Mustard?    :",0

segment .bss
    ;8 ingredients
    ;   0        1       2       3       4       5       6      7    null
    ;lettuce, cheese, tomatoe, onion, pickle, ketchup, mayo, mustard \0
    order resd 9

segment .text
   global  asm_main

asm_main:
   push   ebp
   mov    ebp, esp
   ;********** CODE STARTS HERE **********


        ;;;;;;;;;;;;;;;;
        ;INIT
        ;;;;;;;;;;;;;;;;
        mov eax, 0
        mov ecx, 0
        topinit:
        cmp ecx, 8
        jge endinit
        mov DWORD [order + ecx * 4], eax
        inc ecx
        jmp topinit
        endinit:

        ;;;;;;;;;;;;;;;;
        ;ORDER
        ;;;;;;;;;;;;;;;;
        mov eax, welcome        ;display welcome message
        call print_string
               
        mov eax, 0
        mov ecx, 0              ;loop counter
        toploop1:

            cmp ecx, 8
            jge endloop1

            cmp ecx, 0
            je lettuce
       
            cmp ecx, 1
            je cheese
           
            cmp ecx, 2
            je tomatoe
           
            cmp ecx, 3
            je onion
           
            cmp ecx, 4
            je pickle
           
            cmp ecx, 5
            je ketchup
           
            cmp ecx, 6
            je mayo
           
            cmp ecx, 7
            je mustard
           
        next:
            inc ecx
            jmp toploop1
        endloop1:
            jmp endorder
       
        lettuce:
            mov eax, lettuceprompt    ;set lettuce prompt
            jmp readinput

        cheese:
            mov eax, cheeseprompt     ;set cheese prompt
            jmp readinput

        tomatoe:
            mov eax, tomatoeprompt    ;set tomatoe prompt
            jmp readinput

        onion:
            mov eax, onionprompt      ;set onion prompt
            jmp readinput
           
        pickle:
            mov eax, pickleprompt     ;set pickle prompt
            jmp readinput
           
        ketchup:
            mov eax, ketchupprompt    ;set ketchup prompt
            jmp readinput                                   

        mayo:
            mov eax, mayoprompt       ;set mayo prompt
            jmp readinput   
           
        mustard:
            mov eax, mustardprompt    ;set mustard prompt
            jmp readinput               

        readinput:
            call print_string         ;display prompt to screen
            call read_char            ;enter y/n
            mov cl, al                ;save input
            call read_char            ;\n
            call print_nl
            call print_char
            cmp cl, 'y'               ;add ingredient?
            je addtopping
            jmp next
           
        addtopping:
        mov eax, ecx
        call print_int
        call print_nl
        mov DWORD [order + ecx * 4], 1  ;set 1 for yes
        mov eax, 0
        jmp next
       
        endorder:
     
        ;;;;;;;;;;;;;;;;
        ;PRINT
        ;;;;;;;;;;;;;;;;
        call print_nl   ;newline
        mov ecx, 0
        toploop2:
        cmp ecx, 8
        jge endloop2
       
        mov eax, DWORD [order + ecx * 4]
        call print_int
        call print_nl
       
        inc ecx
        jmp toploop2
       
        endloop2:     

   ; *********** CODE ENDS HERE ***********
   mov      eax, 0
   mov      esp, ebp
   pop      ebp
   ret