Hello everyone,
Sorry if my post is disturbing but I really need your help with this one.
A good a friend o my need to make 3 programs in assebly z80 language for a school project.

1st program:
Categorize the content of memory from FC00H until FFFF at ascending numerical order

2nd program:
registers in the memory from address FC00 until FFFF the content 00-01-02-… FF

3nd program
Multiply two 8bit numbers that are found in the memory and the result going to the memory [exp] (FC00) * (FC01) = (FC04) (FC03)
msb lsb

Any help would make us really happy
Thank you so much for your time
1) This is 4*256=1024 memory locations, so there are duplicates (not a problem, just an observation). Do you know what kind of sort you want to use?

2) Are you saying you want to store $00 in $FC00, $01 in $FC01, etc? Note that $FF will be stored in $FCFF, so what goes in $FD00?

3) This one's much easier. A quick Google search reveals a page I've used several times to help with Doors CS, http://baze.au.com/misc/z80bits.html. Their code for multiplying two 8-bit numbers:

Input: H = Multiplier, E = Multiplicand, L = 0, D = 0
Output: HL = Product

Code:
   sla   h      ; optimised 1st iteration
   jr   nc,$+3
   ld   l,e

   add   hl,hl      ; unroll 7 times
   jr   nc,$+3      ; ...
   add   hl,de      ; ...


Notes on this: You'll want a ld l,0 \ ld d,0 before, obviously, as per the inputs. At the end, you'll want:


Code:
ld a,h
ld ($FC04),a
ld a,l
ld ($FC03),a


Which stores MSB, LSB to $FC04 and $FC03 respectively (this is little-endian, is that what you're trying to do?)

So now our complete code is:


Code:
   ld d,0
   ld l,0
   sla   h      ; optimised 1st iteration
   jr   nc,$+3
   ld   l,e

   add   hl,hl      ; unroll 7 times
   jr   nc,$+3      ; ...
   add   hl,de      ; ...

   ld a,h
   ld ($FC04),a
   ld a,l
   ld ($FC03),a


Now, as for the unrolling part. That means that you need to repeat those three lines 6 more times for 7 total times. The speediest method is to copy and paste six times. However, I'm going to assume the negligible speed hit of saving space is better in this case, so we'll put it in a loop. The register b is used as an iterator:


Code:
   ld d,0
   ld l,0
   sla   h      ; optimised 1st iteration
   jr   nc,$+3
   ld   l,e
   ld   b,7

MultLoop:
   add   hl,hl      ; unroll 7 times
   jr   nc,$+3      ; ...
   add   hl,de      ; ...
   djnz MultLoop

   ld a,h
   ld ($FC04),a
   ld a,l
   ld ($FC03),a


The djnz decrements b, then jumps to MultLoop if it's still not zero. Otherwise, it continues past the djnz. The final step you need to add is load in H and E:


Code:
   ld a,($FC00)
   ld h,a
   ld a,($FC01)
   ld e,a

   ld d,0
   ld l,0
   sla   h      ; optimised 1st iteration
   jr   nc,$+3
   ld   l,e
   ld   b,7

MultLoop:
   add   hl,hl      ; unroll 7 times
   jr   nc,$+3      ; ...
   add   hl,de      ; ...
   djnz MultLoop

   ld a,h
   ld ($FC04),a
   ld a,l
   ld ($FC03),a


I'm curious, what kind of school project is this for?
First of all thank you KermMartian for your reply. We appreciate the fact you spend time to help us. We wish your kindness will be returned to you a 1000 times.

The first program checkes the memory numbers and put them in order the result must be something like this (FC00H)-> 00, (FC01H)-> 01, (FC02H)-> 02,...,(FFFFH)-> FF.
There have to be duplicates cause the memory is too big.

For the 2nd program I gues the result will something like this (FC00H)-> 00, (FC01H)-> 01,...,(FCFFH)-> FF,
(FD00H)-> 00, (FD01H)-> 01,...,(FDFFH)-> FF,
...etc

For the 3rd (FC04H)-> MSB, (FC03H)-> LSB

I'm sending you an exaple from how the program should look:

Code:

;This program fill 16*16=256 memory
;locations with the character 44.

START:   LD HL,6000H
   LD E,10H
LOOP1:   LD D,10H
   LD A,44H
LOOP2:   LD (HL),44H
   INC HL
   DEC D
   JP NZ,LOOP2
   DEC E
   JP NZ,LOOP1
   RST 38H
   END

This is project for microcomputers lesson in greek technical school
Thats all that I can tell from the regarding what my friend told me.
We are so thankful for your help
Regarding the code you just posted, that's fairly unoptimized. How about:


Code:
;This program fill 16*16=256 memory
;locations with the character 44.

START:   LD HL,6000H
   LD B,0
LOOP:   LD (HL),44H
   INC HL
   DJNZ LOOP
   RST 38H
   END


I'm not sure exactly why you're resetting to 38h; I assume it's something with your particular device. Anyway, as far as your Part 3 goes, the code I posted should work. Part 2 is trivial (I'll type it the way your code looks):


Code:
START:
    LD HL,0FC00H
    LD DE,400H
    XOR A
LOOP:
    LD (HL),A
    INC A
    INC HL
    DEC DE
    LD A,D
    OR E
    JR NZ,LOOP
    RST 38H
    END


For part 1, you have to chose a type of sorting first. May I recommend glancing at http://en.wikipedia.org/wiki/Sorting_algorithm?
38h is (always) an ISR (fine, only if you use interrupts in your device), why would you rst to that, anyway? If you really need that to fire, just 'halt'.
The Tari wrote:
38h is (always) an ISR (fine, only if you use interrupts in your device), why would you rst to that, anyway? If you really need that to fire, just 'halt'.
I thought the same thing, but now I'm assuming it's part of the assignment. I suppose it has to do with however their testbed is set up?
To tell you the truth I have no idea why we use that command. That's what we've been taught to. We are using this assebler



KermMartian
I cant tell which sort should I use at first program. I was thinking something which would compare 2 numbers by subtraction and carry check. Or whatever you think should work fine
Hmm, this is the MPF-1B:
http://www.sbprojects.com/projects/mpf1/mpf1.htm

Before we get to the sorting one, do Parts 2 and 3 make sense to you? I think those are both done; have you tested them?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement