bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gas/27878] New: [z80-unknown-elf]: ld (hl),<16 bit immediate> shoul


From: petemoore at gmx dot net
Subject: [Bug gas/27878] New: [z80-unknown-elf]: ld (hl),<16 bit immediate> should fail assembly
Date: Mon, 17 May 2021 20:00:59 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27878

            Bug ID: 27878
           Summary: [z80-unknown-elf]: ld (hl),<16 bit immediate> should
                    fail assembly
           Product: binutils
           Version: 2.36.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gas
          Assignee: unassigned at sourceware dot org
          Reporter: petemoore at gmx dot net
                CC: sergey.belyashov at gmail dot com
  Target Milestone: ---
            Target: z80-unknown-elf

```
$ # GAS version
$ z80-unknown-elf-as --version
GNU assembler (GNU Binutils) 2.36.1
Copyright (C) 2021 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `z80-unknown-elf'.

$ # Sample assembly file
$ cat test.asm

ld (0x1234), hl
ld (hl), 0x1234

$ # Assembly doesn't fail nor warn that a constant is out-of-range, but instead
truncates the value 0x1234 to 0x34
$ z80-unknown-elf-as -o test.o test.asm && z80-unknown-elf-objdump -d test.o

test.o:     file format elf32-z80


Disassembly of section .text:

00000000 <.text>:
   0:   22 34 12        ld (0x1234),hl
   3:   36 34           ld (hl),0x34
```


Some Z80 operations support loading a 16 bit value to memory (e.g. ld (nn),hl)
but others only support loading 8 bit values (e.g. ld (hl),n).

It can be easy to forget when initialising a 16 bit constant value at a fixed
address, whether you need a constant address in the instruction and the value
in a register, or the address in a register and a constant value in the
instruction.

The assembler doesn't fail nor throw a warning if you try to load a 16 bit
constant value into (hl), but instead silently truncates it to 8 bits. A
warning or failure would be desirable for the assembly of _any_ instruction
where the immediate constant is out-of-range for the given instruction. I only
noticed it so far with the the ld (hl),n instruction, but it would be good to
test all instructions that take 8 bit immediates with an out-of-range 16 bit
value, to see if any other instructions exhibit the same issue.

I'm happy to help with writing tests etc, if I can be given some initial
guidance.

Many thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]