2 Replies - 3517 Views - Last Post: 21 November 2012 - 05:20 PM

#1 StNtMaN  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 09-December 11

Pep/8 Menu Input Program Issue

Posted 15 November 2012 - 09:02 PM

Create a simple calculator that has the following menu:

A ADD
S SUB
N NEG
Q Quit

Input option: A
Input number: 11
Ans = 11

Input option: S
Input number: 5
Ans = 6

Input option: N
Ans = -6

Input option: A
Input number: 10
Ans = 4

Input option: Q

Have the program print the menu once and have your answer set to zero (can't trust it). Then use the CHARI to input the command and the DECI and DECO to input and output the answer. You'll have to use the conditional branches, of course.

Note: Do NOT have a branch at the top like with the textbook examples. Place your data and the END of the program (before ."END") and have your program start at location 0 (with OUT the first branch). I'll ding you a point if you do.

Here is what I have so far...

A:       .BLOCK  1
S:       .BLOCK  2
N:       .BLOCK  3
main:         LDA      0,i 
again:   CHARI   A,d 
         LDBYTEA A,d
         CPA     '\n',i
         BREQ    again
again2:  CHARI   S,d
         LDBYTEA S,d
         CPA     '\n',i
         BREQ    again2
again3:  CHARI   N,d
         LDBYTEA N,d
         CPA     '\n',i
         BREQ    again3

choicea:       .ASCII  "Input option: A"
choices:       .ASCII  "Input option: S"
choicen:       .ASCII  "Input option: N" 

.end



Any help would be appreciated....I have barely any knowledge in assembly language and pep/8. I mainly work with java. A for effort??? heh!

Is This A Good Question/Topic? 0
  • +

Replies To: Pep/8 Menu Input Program Issue

#2 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 615
  • Joined: 03-April 12

Re: Pep/8 Menu Input Program Issue

Posted 20 November 2012 - 06:02 AM

Try to wtite the code first as VERY SIMPLISTIC java.
Only "static" single dimension arrays allowed.
Any string manipulation to be done character by character.

What your code does now (maybe) is:

main:         LDA      0,i ; // Clear A
05
again:   CHARI   A,d ; // Input character to memory location A
06
         LDBYTEA A,d ; // Move character from the memory location A to register A
07
         CPA     '\n',i ; // Compare character in register A to newline
08
         BREQ    again ; // If characters are same, goto "again" ...
09
again2:  CHARI   S,d  ; // ... else input character
10
         LDBYTEA S,d ; // Move the character to A
11
         CPA     '\n',i ; // Compare Character to newline
12
         BREQ    again2 ; // If characters are same, goto "again2" ...
13
again3:  CHARI   N,d ; // ...
14
         LDBYTEA N,d
15
         CPA     '\n',i
16
         BREQ    again3



My comments are based mostly on guesses, because I found the instruction mnemonics, but no specifications what the instructions actually do.
(0100 1aaa CHARI Character input d, n, s, sf, x, sx, sxf )

Does that help?

This post has been edited by turboscrew: 20 November 2012 - 06:09 AM

Was This Post Helpful? 0
  • +
  • -

#3 StNtMaN  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 09-December 11

Re: Pep/8 Menu Input Program Issue

Posted 21 November 2012 - 05:20 PM

Hey thanks turbo, but after a little perseverence I finally figured it out!
Here you go:

STRO menu1,d
STRO menu2,d
STRO menu3,d
STRO menu4,d
CHARO '\n',i

start:   STRO option,d
CHARI choice,d
LDBYTEA choice,d
CPA 'a',i
BRNE ifS
STRO number,d
DECI num,d
LDA total,d
ADDA num,d
STA total,d
STRO ans,d
DECO total,d
CHARO '\n',i
BR start

ifS:     CPA 's',i
BRNE ifN
STRO number,d
DECI num,d
LDA total,d
SUBA num,d
STA total,d
STRO ans,d
DECO total,d
CHARO '\n',i
BR start

ifN:     CPA 'n',i
BRNE ifQ
LDA total,d
NEGA
STA total,d
STRO ans,d
DECO total,d
CHARO '\n',i
BR start

ifQ:     STOP


menu1: .ASCII "a - ADD \x00"
menu2: .ASCII "s - SUB \x00"
menu3: .ASCII "n - NEG \x00"
menu4: .ASCII "q - Quit \x00"

ans: .ASCII "Ans = \x00"
number: .ASCII "Input number: \x00"

num: .BLOCK 2
total: .BLOCK 2
choice: .EQUATE 4

option: .ASCII "Input option: \x00"

.END



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1