# MaxCoderz

 All times are UTC

 Page 1 of 1 [ 12 posts ]
 Print view Previous topic | Next topic

How many did you get right?
 0~1 80% [ 4 ] 2~4 20% [ 1 ] 5~7 0% [ 0 ] 8~9 0% [ 0 ] 10 0% [ 0 ]
Author Message
 Post subject: RevSoft Code GamePosted: Sun 30 Jul, 2006 11:27 am
 Calc King

Joined: Sun 26 Dec, 2004 5:27 am
Posts: 2457
Location: SXIOPO = Infinite lives for both players
We had a code game over at RevSoft, but we ran out of ideas after a while and it became a routine contest. So since some of you don't drop by RevSoft that often, I'll post the question here so you can play. Most of it is finding the most optimised way in z80 code, others are knowledge of the cpu.

Don't cheat, I'll know if your cheating because I know who knows the answers and who doesn't. And be careful, some things that seem obvious or well known are not correct.

Last the questions are in no particular order, difficulty will vary as you progress.

Question 01 - Spencer's:
Turn an 8-bit signed number into a 16-bit signed number. You do this by propagating the sign bit all the way to the most significant bit.
%10110110 turns to %1111111110110110,
%00000001 turns to %0000000000000001
Code:
inputs:  a  - 8-bit signed number
outputs: bc - same 16-bit signed number

Question 02 - Jim e's:
Code:
ld hl,(source)
ld de,(destination)
ld bc,(length)
ldir

How many bytes is this, ANSWER WITH OUT LOOKING AT GUIDES!!! Also tell why your answer is correct!

Question 03 - NanoWar's:
Code:
label: jr label

Will the hex value be A, B, C, D or E?
A. 18 FE
B. 18 FF
C. 18 00
D. 18 01
E. 18 02

Question 04 - Jim e's:
okay here is an easy one I expect everyone to get it.
Code:
di
ld a,r
ld c,a
ld b,a
ld hl,(\$8000)
ld ix,(\$8002)
label:
ex de,hl
djnz label
ld a,r

Relative to C what does A contain at the end of this code.

Hint: its an equation I don't expect an exact number.

Question 05 - Jim e's:
Name the registers in the CPU. If they can be paired, name them by their pairs. DO IT FROM MEMORY!

Question 06 - Jim e's:
Super duper easy!

P/V flags detects Parity or overflow, Do it from memory.

Question 07 - KevinJB's:
Here's an easy one:

Code:
xor a
ld (sram), a
ld (sram+1), a
ld (sram+2), a
ld (sram+3), a
ld hl, 255
push hl
push hl
pop hl
ld (sram), hl
pop hl
ld (sram + 1), hl

What in order does sram, sram + 1, sram + 2, and sram + 3 hold?

Question 08 - Jim e's: ( altered from the original )
Reverse the bits of C and place it into A. So %10100000 would be come %00000101
Do this without the RLA or RRA instruction.

FASTEST CODE WINS.

Question 09 - Stickmanofdoom's:
Write a routine that will add A to DE (unsigned) without an "add reg16,reg16" instruction like "add hl,de".
I've posted something about this before, but I can't come up with anything else that would fit this game.

Editor Jim e's Note: Speed determines winner, since probability may play a role in this, post multiple answers.

Question 10 - KevinJB's:
Explain each bit in the Flag register. Sound good?

That's the end of the quiz. I'll post the answers later, most of it is simple. Some of it is pretty tough. Feel free to post your own quiz questions.

To be nice Hide you answers when you post them, The board color is #cfcfbf, So to hide text it would be.
Hidden Text
Hidden Text

I really want to see MC's brightest participate in this. Because even Spencer only got one correct. Haha, burned him while he is on vacation.

(Gratuitous blank space to reduce answer spoilage.)

_________________

Top

 Post subject: Posted: Sun 30 Jul, 2006 4:50 pm
 Calc Wizard

Joined: Sun 19 Dec, 2004 9:02 pm
Posts: 585
Location: Sweden
If you already know who knows what, why did you bother making this thread?

Top

 Post subject: Posted: Sun 30 Jul, 2006 8:01 pm
 MCF Legend

Joined: Mon 20 Dec, 2004 8:45 am
Posts: 1601
Location: Budapest, Absurdistan
Answer to question 8: ld b,aligned_reverse_lut >> 8 \ ld a,(bc)

_________________
The Independent Z80 Assembly Guide
Acelgoyobis
PindurTI

Top

 Post subject: Posted: Mon 31 Jul, 2006 1:19 am
 Calc King

Joined: Sun 26 Dec, 2004 5:27 am
Posts: 2457
Location: SXIOPO = Infinite lives for both players
CoBB wrote:
Answer to question 8: ld b,aligned_reverse_lut >> 8 \ ld a,(bc)
...You're an evil bastard. I shouda put a size limit.

Come on, Answer the rest or post a new question.

_________________

Top

 Post subject: Posted: Mon 31 Jul, 2006 6:18 am
 MCF Legend

Joined: Mon 20 Dec, 2004 8:45 am
Posts: 1601
Location: Budapest, Absurdistan
These questions seem to be a bit unchallenging for me, although I'm really curious who can account for the undocumented flag bits by heart.

Okay, here's one I hope some will find interesting...

Question 11:
It is a well-known fact that
Code:
call Routine
ret

can be optimised into
Code:
jp Routine

However, you can't do this in every case. Present a practical (i. e. non-fabricated) scenario where this trick would lead to an error and explain why.

_________________
The Independent Z80 Assembly Guide
Acelgoyobis
PindurTI

Top

 Post subject: Posted: Mon 31 Jul, 2006 7:13 pm
 Calc King

Joined: Sun 27 Mar, 2005 4:06 am
Posts: 2195
Location: sleeping
I knew the flags by heart.

In a routine that pops the stack in order to get the data at the previous location. Something like a string routine like this
call drawstring
.db "Blah",0
ret
[...]
drawstring:
pop hl
bcall(_puts)
jp(hl)

Long explaination and example code.

_________________

Top

 Post subject: Posted: Mon 31 Jul, 2006 10:07 pm
 MCF Legend

Joined: Mon 20 Dec, 2004 8:45 am
Posts: 1601
Location: Budapest, Absurdistan
threefingeredguy wrote:
I knew the flags by heart.

I looked at the Revsoft topic, and saw no correct solutions there. (Not even from Jim e! ) You only recited the names but didn't explain as the question requested. No-one seemed to know how the N and H flags work, and also no-one explained what overflow means exactly. The general knowledge of the S flag is also quite shaky from the looks of it. And well, no-one knew what the 'undocumented' flags do, even though their value is quite predictable in most cases (they both do have a primary function).

Educate yourselves.

As for your answer to 11, it's unfortunately irrelevant. Note that the original call has to be immediately followed by a ret! Simply replacing a lone call with a jump would be nonsense in any program.

_________________
The Independent Z80 Assembly Guide
Acelgoyobis
PindurTI

Top

 Post subject: Posted: Mon 31 Jul, 2006 11:26 pm
 Calc King

Joined: Sun 27 Mar, 2005 4:06 am
Posts: 2195
Location: sleeping
I noticed that I didn't have the ret immediately after, I just couldn't think of anything else.

_________________

Top

 Post subject: Posted: Tue 01 Aug, 2006 1:34 am
 Calc Master

Joined: Mon 20 Dec, 2004 10:01 pm
Posts: 1110
Location: In the state of Roo Fearing
If you would normally pass parameters to the subroutine on the stack, but instead of call sub \ ret you do jp sub, the subroutine will still expect the return address to be at the top of the stack, so its parameters will be misread and cause general troubles when it takes too much stuff off the stack.

Of course, in this case the programmer would be stupid for passing by stack and not calling... One would have to at least push the return address that the ret you saved would have gone to on the stack...

I guess this is kind of a "duh" situation, but it isn't fabricated!

_________________

Top

 Post subject: Posted: Tue 01 Aug, 2006 5:01 am
 Calc King

Joined: Sun 26 Dec, 2004 5:27 am
Posts: 2457
Location: SXIOPO = Infinite lives for both players
CoBB wrote:
I looked at the Revsoft topic, and saw no correct solutions there. (Not even from Jim e! ) You only recited the names but didn't explain as the question requested. No-one seemed to know how the N and H flags work, and also no-one explained what overflow means exactly.
We don't all write books on z80. I believe the title of your thesis was "Some Smart Shit" wasn't it?

For 11 I can only imagine a good reason being when the function being called expects there to be a return to the calling function. For example.

Code:
Main
call  check
;do stuff
ret

Check:
ld a,(somevaule)
cp 3
call z,somecrap
cp 9
call z,somecrap
cp 17
call z,somecrap
cp 29
ret nz
jp somecrap

somecrap:
ld hl,(anothervaule)
inc hl
ld (anothervaule),hl
ld a,h
or l
ld a,0
pop hl

okay maybe not the best example or even the best answer, But Im not so sure that argument passing would falter. My reason is that this something that you don't directly use the SP register for rather an indexing register with sp in it. You could pass the arguments after the reutrn adress. example:

Code:
function:
push ix
ld ix,sizeof_args
ld sp,ix

;do stuff

ld de,-sizeof_args
ld sp,ix
pop ix
ret

Even if the return address was on top of the stack it would still have to re-adjust the stack level.

Not really sure on the situation where that would fail. It'd be rather particualr I'd imagine.

_________________

Top

 Post subject: Posted: Tue 01 Aug, 2006 6:12 am
 MCF Legend

Joined: Mon 20 Dec, 2004 8:45 am
Posts: 1601
Location: Budapest, Absurdistan
Jim e wrote:
We don't all write books on z80. I believe the title of your thesis was "Some Smart Shit" wasn't it?

Note that I use the word 'smart' in the same sense as Ben. Seriously, everyone who writes some Z80 code should be perfectly familiar with the S, Z, P/V and C flags at least. The other four are much less important, being either 'undocumented' or only used by DAA.

These examples are certainly better. I encountered this very problem when coding some collision detection that needed to run identical code with different parameters four times. This code also called a subroutine, and it was possible to determine the outcome of the whole thing within this second call, allowing a fast pop \ ret escape. It took some time to hunt down that bug.

_________________
The Independent Z80 Assembly Guide
Acelgoyobis
PindurTI

Top

 Post subject: Posted: Tue 01 Aug, 2006 6:42 am
 Calc King

Joined: Sun 26 Dec, 2004 5:27 am
Posts: 2457
Location: SXIOPO = Infinite lives for both players
Its pretty much what I saw over done in the loom source. I wish wakamol the best of luck.

Well original this was more of a competition rather than a quiz, so best answer is the correct answer. 1, 2, 4, and 9 are the ones I like, But for some god awfull reason I couldn't write 8 for the answer I wanted....

_________________

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 12 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ General    News and Information    General TI Discussion    Off Topic    Announce Your Projects    Pixel Art Projects    Staff Side Projects & Featured Projects    Aether 3D    BBC BASIC    Latenite, Brass and EarlyMorning    Metroid    Nostromo    Smash Bros    Super Mario - and the Elemental Crystal    Tankies    xLIB    solidFRAME Products    Staff Side Products & Featured Products    Desolate    Grayscale Dev Kit    The Verdante Forest    Trapped    Discontinued Projects Programming    Programming Help    Program Ideas    Programming Competition