Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Computer architecture help

Status
Not open for further replies.

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
Hi, i have a question on computer architecture and its very difficult. My college teacher said the example given has alot of what we need to figure it out so ill post that along with the question as an image

So far i have...

Code:
IN A, (0xff)
XOR A, 0x1b
JP LOOP1
OUT (0xfb), 0xaa

I know its wrong but i cant get my head around it, does anyone have any ideas? anything is appreciated

help.png

also if you need the z80 instruction set, here is a link to it - https://clrhome.org/table/
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,854
Helped
1,815
Reputation
3,640
Reaction score
1,780
Trophy points
1,393
Location
USA
Activity points
59,349
You need to check that the value produced by the XOR is 0 (i.e. matches 0x1b) if its 0 you output the status byte 0xaa, otherwise you jump back to the IN A line.

I'm sure the z80 has some sort of compare of some sort...hmm looks like a cp instruction and then jp instruction that looks at the flags.

I'll admit I've never written z80 assembly so there might be a better way to do this.
 

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
yes my college teacher said about cp instructions
 

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
im not sure if my replys are working but my college teacher mentioned the cp instructions and that i should use it.
Does anyone know how specificly?
to my understanding it compares 2 value by subtracting one from another or something, im really not sure
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,854
Helped
1,815
Reputation
3,640
Reaction score
1,780
Trophy points
1,393
Location
USA
Activity points
59,349
The following link shows how to use the CP instruction.
https://z80-heaven.wikidot.com/instructions-set:cp

You want to use CP n n is your 0x1b constant, which means you don't need the XOR as it's not needed.

So what you want to do is the following:

1. read input
2. compare to 0x1b
3. jump on Z set to (5. output status 0xaa)
4. fall through, Z not set jump back to (1. read input)
5. output status 0xaa
6. jump to (1. read input)

It would probably be easier if I drew a flow chart, but I don't have the time.
 

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
Thankyou for the help but how would that be written, like this?

IN A, (0xff)
CP A, 0x1b
OUT (0xfb), 0xaa
JP LOOP1
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,854
Helped
1,815
Reputation
3,640
Reaction score
1,780
Trophy points
1,393
Location
USA
Activity points
59,349
you left out the jump on a Z (i.e. stands for zero result) after you compare.

You should have looked at this page for the JP instruction options. Besides that you didn't follow the exact ordering I posted in #5. Read that until you understand what I'm doing.
 

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
Ok thankyou very much for your time i am determinded to get this right

IN A, (0xff) - ok this reads the input from port 0xff

CP A, 0x1b - this compares that value to 0x1b

JP Z, 4 - this jumps to the output on line 4 i think

OUT (0xfb), 0xaa - this will output the value 0xaa to port 0xfb

JP LOOP1 - this will loop back around


im not sure what "fall through, z not set jump back to 1. read input" means or the instruction to do it,
im really sorry if its fustrating when im not getting it right but im trying my hardest, please bare with me, i am very thankful of you helping me
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,854
Helped
1,815
Reputation
3,640
Reaction score
1,780
Trophy points
1,393
Location
USA
Activity points
59,349
JP Z, 4 - this jumps to the output on line 4 i think
You don't want a hardcoded address, use a label, let the assembler figure out the adddress to put in the instruction.

Jason12345 said:
im not sure what "fall through, z not set jump back to 1. read input" means or the instruction to do it,
im really sorry if its fustrating when im not getting it right but im trying my hardest, please bare with me, i am very thankful of you helping me
When a jump instruction isn't taken (jump condition is not met) the program execution "falls through" (i.e. goes to the next instruction), so following the jump instruction you want to add code that say what you do when the input byte does not match 0x1b. See line 4 in post #5.

so as an example:
Adding two number that will result in a carry...
Code:
START:    IN A, (0xff)        # read input from port 0xff
          ADD 0x80            # add 0x80 to A
          ?? ?, CARRY         # if there is a carry (i.e. A+0x80 has a result with 0x1??)
          OUT (0xfb), A       # spit out the sum on port 0xfb when there isn't a carry
          ?? START            # look for more inputs
CARRY:    OUT (0xfb), 0x01    # spit out carry
          OUT (0xfb), A       #   then the sum on port 0xfb when there is a carry
          ?? START            # look for more inputs

I'm leaving it up to you to figure out what instructions to use where the ?s are.
Pardon any syntax errors, I have no clue what the assembler requires. You should be able extrapolate what you are trying to implement by looking at this code.
 
Last edited:

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
You don't want a hardcoded address, use a label, let the assembler figure out the adddress to put in the instruction.

ok does that mean i should replace JP Z, 4 with JP C, CARRY like you did in the example

I have added a line under the jump to say if the condition isnt met, it will jump to the start again. i used your example to replace JP LOOP1 with JP START

im not smart when it comes to stuff like this, it confuses me alot. will you please let me know if i did anything wrong?


IN A, (0xff) - ok this reads the input from port 0xff

CP A, 0x1b - this compares that value to 0x1b

JP C, CARRY - this jumps to the output on line 4 i think

JP START - so after the jump condition isnt met, it will loop back around to 1 and try to read the input again

OUT (0xfb), 0xaa - this will output the value 0xaa to port 0xfb

JP START - this will loop back around


thankyou for your time again
 

Allen6502

Advanced Member level 4
Joined
Nov 22, 2008
Messages
119
Helped
33
Reputation
66
Reaction score
31
Trophy points
1,308
Location
Borneo Island
Activity points
2,047
Ok thankyou very much for your time i am determinded to get this right

IN A, (0xff) - ok this reads the input from port 0xff

CP A, 0x1b - this compares that value to 0x1b

JP Z, 4 - this jumps to the output on line 4 i think

OUT (0xfb), 0xaa - this will output the value 0xaa to port 0xfb

JP LOOP1 - this will loop back around


im not sure what "fall through, z not set jump back to 1. read input" means or the instruction to do it,
im really sorry if its fustrating when im not getting it right but im trying my hardest, please bare with me, i am very thankful of you helping me

I think it is more like this..........

Code:
LOOP1: IN A, (0XFF)    ;GET INPUT IN ACC
           CP A, 0X1B     ;COMPARE WITH 0X1B
           JNZ    LOOP1   ;IF NOT SAME THEN GO BACK
           LD A, 0XAA     ; LOAD ACC WITH 0XAA 
           OUT A,(0XFB)  ;OUT 0XAA TO PORT FB
           END

Sorry my Z80 memory is very, very rusty.

Allen
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,854
Helped
1,815
Reputation
3,640
Reaction score
1,780
Trophy points
1,393
Location
USA
Activity points
59,349
I give up...here. study it...understand it.

Code:
START:    IN A, (0xff)      # port 0xff => A
          CP 0x1b           # compare A with 0x1b (sets/clears Z flag)
          JP NZ NOTEQUAL    # if Z == 0, jump to START
          LD A, 0xaa        # thanks Allen, didn't look at these instructions
          OUT A, (0xfb)     #   ...Z==1, output 0xaa
NOTEQUAL: JP START          # jump back to START
I noticed an optimization with jumping back to the start directly if the Z flag is clear.
If the Z flag is set then output 0xaa and jump back to the start.

You should probably learn how to draw up a flowchart so you can understand the logic involved.

- - - Updated - - -

Looks like I have an extra jump :p never claimed to be a software type. I actually can't stand writing software, and tolerate writing Perl scripts. ;-)

...so don't refer to my Verilog/VHDL as software :evil:
 
Last edited:

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
thankyou both of you for helping me, i will show my computer architecture teacher and see what he thinks. Without u guys im sure i wouldnt of got this so your help is very much appriciated :smile::thumbsup:
 

Allen6502

Advanced Member level 4
Joined
Nov 22, 2008
Messages
119
Helped
33
Reputation
66
Reaction score
31
Trophy points
1,308
Location
Borneo Island
Activity points
2,047
thankyou both of you for helping me, i will show my computer architecture teacher and see what he thinks. Without u guys im sure i wouldnt of got this so your help is very much appriciated :smile::thumbsup:


You're welcomed.:oops:

I checked with my Z80 books just now and found some mistakes in my code. The correct one is as below....

Code:
LOOP1: IN A, (0xFF)   ;GET INPUT IN ACC
       CP 0x1B        ;COMPARE WITH 0x1B
       JP NZ, LOOP1   ;IF NOT SAME THEN GO BACK
       LD A, 0xAA     ;LOAD ACC WITH 0XAA 
       OUT (0xFB),A   ;OUT 0xAA TO PORT FB
       END

See that CP compares a byte, register, (HL), (IX+d) or (IY+d) against Acc. So A in the instruction is optional. And I must have mixed up JP NZ with JNZ of 8051.

Allen
 

Jason12345

Newbie level 5
Joined
Jan 29, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
58
i showed my teacher today and he said everything was correct, thanks again everyone :thumbsup:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top