Assembler trick: inline strings

Quite often, we need to send strings to a computer. Usually, there is a section in your code where you define the message with a label:

;string is terminated with null
MsgHelloWorld: .asciz "Hello World!\r\n"

;subroutine to print strings
putstr: 
    ld a,(hl)
    or a
    ret z
    call putchar
    inc hl
    jr putstr

main:
    ld hl,#MsgHelloWorld
    call putstr
    halt

With a bit of extra code, we can make some code with embedded strings.

main:
    call   putstr_imm
    .asciz "Hello World\r\n"

    call   putstr_imm
    .asciz "Hello World again\r\n"
    halt

;subroutine to print inline strings
putstr_imm:
    ;this exchange the stack pointer (SP) with HL
    ex sp,hl

    ;at this point, HL points to the code after the call,
    ;but we placed data instead, terminated with a null.
    ;So we skip the data while printing it. 
    ;When done, normal code follows
put1:
    ld a,(hl)
    or a
    jr nz,put_ret ;if null detected we resume code
    call putchar ;else we print bytes
    inc hl
    jr put1
put_ret:
;restore the stack pointer which point to the code after the string
    ex sp,hl
    ret

 

Posted in assembler, Software, Z80 | Tagged , , , | Leave a comment

Can a rock reflect light?

Many flat earth advocates mention that the moon emits its own light because rocks “don’t reflect light”.  I’ve done an experiment.

Here’s a decent rock. Not black, not white, just a reasonable gray.

DSCN0001

The experiment setup: a white melamin board as screen, the rock, and a laser pen at right directed at about 45 degree on the rock.

DSCN0002

We don’t see much reflection on this picture, since the flash was used.

DSCN0003

Now, without flash, we clearly see a diffused reflection.

DSCN0004

So the moon reflecting the sunlight is plausible.

Posted in flat earth (debunking) physics | Tagged , | Leave a comment

AVR Man and Wasteman

For those reading my previous post, I’m still alive! (And human!)

While I’m tinkering with various processors, one of my favorites is the Atmel microcontrollers. A while ago, they had some comicbook style hero called AVR Man and his nemesis Wasteman. I came up with an amusing story here. If I was good at drawing, I’d make a comic strip:

1st picture:
Wasteman: “Hey, Batmel! There’s a contest for (something about microcontrollers)”

AVR Man: “It’s AVR Man, don’t forget this, Wasteman!”

2nd picture:
At the contest:
Wasteman: “Sure, with my old NMOS Z80, there is no way I’m gonna lose.”

AVR Man: “That’s what we’ll see, Wasteman! I’m participating too!”

3rd picture:
During the contest:
Wasteman: “Dammit! Now the battery’s dead!”

4th picture:
(Wasteman attempts to cheat by charging his dead battery, but it’s not allowed in the rules)
Wasteman: “But I’m not giving up this easily… A quick charge and I’ll make it to the end.”

5th picture:
(caugh red handed by AVR Man and contest officials)
(could use some shadow effects to make AVR Man look like Batman)
Wasteman: “BAT… er… AVR Man!”

AVR Man: “I’m afraid that your cheat was discovered, Wasteman!”

6th picture:
AVR Man: “Fortunately, it’s just a contest, otherwise, you’ll be convicted…”

AVR Man: “of battery charge! Ah! Ah!”

 

Posted in Electronics, Texts | Tagged , , , | Leave a comment

Nobody saw this coming

Nobody saw this coming.

I don’t know how all of this began and when. Trump was reelected with a surprising majority. Or maybe before, when flat earthers reemerged on the web, proclaiming the earth is flat, based on old unscientific books written long before modern science.

Or how the internet web was beginning to have shitty content of people mutilating themselves or attempting to do all sorts of crazy stuff. You may not know this, reader in the future, but the internet allowed us to share almost everything on cyberspace. It allowed all the computers of the whole planet to communicate with all others. And I’m not even talking about the dark web. Who knows what’s on this and I don’t even want to know. Considering the horrific things we get in the news, one can only think that there must be horrifying stuff beyond imagination. Anyway, enough of that.

There was also all that craze about the zombie apocalypse, but of course, it’s just fiction. There was a tremendous increase of violence everywhere. The radical islamists, the numerous shootings in the United-States, etc. The web was regularly predicting the end of the world each year without success, fortunately. The 4 Blood Moons (just a natural phenomenon), the Rapture (it never happened), the Angel Trumpets (fakes). There was so much conspiracies everywhere that nothing seemed believable anymore. Nasa, Moon landings, ISS, pictures from space, and so many more.
It may not be surprising that if the USA was a culture of fakes, US citizens grew tired of all this fakery. YouTube was merely a vent for all those frustrations.

Many virus appeared after the AIDS virus. Fortunately, with modern science, medicine could annihilate even AIDS. But this …

But all that was nothing, compared to that thing. Nobody knows what it is exactly, but it must not touch you in any way or you’re done (I don’t know for sure). The best comparison I can say is that it’s as if a hacker exploited all the biological backdoors of your body. It may rot you, or transform you into a zombie, or whatever else. Yet, I’m not sure, it’s still matter of speculations. We don’t know all the possible vectors of propagation of that horrible thing.
I don’t know how it looks like. The only thing I know is that your instinct kicks in and you have a feeling there is something horribly wrong going on. Pretty much like the suspense music when there is something about to happen.

I don’t know how this will end and if the readers in the future will even be humajkhlkgjjhvm   hgljgjhg    helpjgjklgjkghjkg     oi;lkj;ljlj            fdgsfsa54……………………………….

Posted in Texts | Tagged , | Leave a comment

Spinning ball model

If we were to reproduce a spinning ball holding water, we should have gravitation exceeding the centrifugal acceleration (300 times stronger normally).

The gravity (acceleration) holding the water should be: g = Gm1/R².

Since we will scale down the model, we will need to know the limit to where we can go.
We need to convert m1/R² to use density:

density = mass/volume -> mass = density * volume.
volume of a sphere = 4πr³/3
m1/R² = d1 * 4πR³/3R² = d1 * 4πR/3 where d1 is the earth’s density (5.51g/cm³)

On earth and the scale model, the gravity is g = Gm1/R² = 4πGRd1/3

We can see here that the gravity at “sea” level is proportional to the radius (other values are constants) hence g = kR where k = 4πGd1/3

The centrifugal acceleration is also proportional to the radius: α = ω²r

To not fling everything in space we need to have g ≥ α, or kR ≥ ω²R or k ≥ ω²

So the rotational speed limit doesn’t depend on the radius. This means that we can make a model small enough for experiments.

The limit for the rotational speed is 1.24 mrad/s which is 17 revolutions per day.

Posted in flat earth (debunking) physics | Tagged , | Leave a comment

Problem with assembler files when compiling a C project with SDCC and Codeblocks

I was trying to compile a simple C project (SDCC for Z80) with codeblocks. As usual, I stumble easily on minor problems, taking much time to look up for a solution. This time, it’s a small project that doesn’t want to compile.

Here is the code:

#include

void putchar(char c);


void main(void)
 {
 printf("Hello world\r\n");
 }

void putchar(char c)
 {
 c;
 __asm
 call    0x0529
 __endasm;
 }

What could be simpler? When compiling the file, it generate these messages:

||=== Build: Release in test-vinc (compiler: SDCC Compiler) ===|
 obj/Release/main.asm|156|Error:  missing or improper operators, terminators, or delimiters|
 ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Of course, the project worked fine previously and there’s absolutely nothing wrong in my code. Here are my software versions:

Codeblocks 16.01
SDCC 3.3.2 #8942 (Feb 13 2014)

Well, the solution was simple.

To correct this problem, be sure to specify the particular CPU you’re using. In my case, Z80.

In CodeBlocks’ menu, select Project, Build options,

sdcc-cpu

That’s it! Now it works!

Posted in Electronics, Software | Tagged , | Leave a comment

Altera Quartus, combining Verilog and VHDL

In my previous post, I ported the Multicomp from Grant Searle to an Altera Cyclone II FPGA platform.

The Multicomp peripheral are quite minimal, and I wished to use the on board facilities. Code for these were supplied in Verilog. In my tiny pea brain, I figured that the geniuses at Altera could combine easily Verilog and VHDL code.

As soon as you add the Verilog file in the project, it’s recognized.

verilog

I ran into some errors; “design library work does not contain primary unit”. I tried different syntaxes and solutions found on the web without success, but after some tweaks, I succeeded in compiling the project.

Here is the working solution:

After including the Verilog file, we modify the main VHDL file to connect the new component.

library ieee;
use ieee.std_logic_1164.all;
use  IEEE.STD_LOGIC_ARITH.all;
use  IEEE.STD_LOGIC_UNSIGNED.all;

entity Microcomputer is
    port(-- all the ios, etc);
end Microcomputer;

architecture struct of Microcomputer is

-- Here, we declare the Verilog component.
-- This is a One Wire controller which is connected to a Dallas chip.
component DS18B20_CTL is
    port(-- all the ios, etc);
end component;

begin

-- We instanciate the Verilog component just as another VHDL component.
ow1 : component DS18B20_CTL
port map (-- all the ios, etc);

-- Other VHDL code

end;

It’s as simple as that!

Posted in Electronics, FPGA, Z80 | Tagged | Leave a comment