Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

movzbl instruction can not compile in section 15_Pointers_pt1 and onward #62

Open
davidle2023 opened this issue May 30, 2023 · 2 comments

Comments

@davidle2023
Copy link

Hi There,
There might be an issue with movzbl in section 15_Pointers_pt1 and onward.
Attaching the issue.15.txt for detail description. Thx!!!
Regards
David
P.S.: I am a newbie hence my report can be totally wrong.

issue.15.txt

@the-grue
Copy link
Contributor

Hi @davidle2023 ! I'm going to make an assumption that when Warren made this tutorial, he was using a version of as that would accept the movzbl opcode and generate suitable code. For example, on my Ubuntu 20.04 LTS test machine everything builds fine and runs with the expected results. However, on my Ubuntu 22.04 LTS test machine, I get different results than what you report but it boils down to the same thing:

$ make test15
./comp1 tests/input15.c
cc -o out out.s lib/printint.c
out.s: Assembler messages:
out.s:31: Error: incorrect register %r8' used with l' suffix
out.s:40: Error: incorrect register %r8' used with l' suffix
make: *** [Makefile:34: test15] Error 1

I tested my nasm code against both 20.04 and 22.04 because I was developing on 22.04 and running into errors with as code that magically went away under 20.04. Since my goal was to add nasm output to the existing compilers, I didn't try to fix what I was seeing in the as code.

By the way, I like your report format.

Jim

@HLYTQ
Copy link

HLYTQ commented Apr 26, 2024

int cgloadglob(int id) {
  int r = alloc_register();

  switch (Gsym[id].type) {
    case P_CHAR:
      fprintf(Outfile, "\tmovzbq\t%s(%%rip), %s\n", Gsym[id].name,
	      reglist[r]);
      break;
    case P_INT:
      fprintf(Outfile, "\tmovzbl\t%s(\%%rip), %s\n", Gsym[id].name,
	      dreglist[r]);  // There!!! reglist[r] => dreglist[r]
      break;
    case P_LONG:
    case P_CHARPTR:
    case P_INTPTR:
    case P_LONGPTR:
      fprintf(Outfile, "\tmovq\t%s(\%%rip), %s\n", Gsym[id].name, reglist[r]);
      break;
    default:
      fatald("Bad type in cgloadglob:", Gsym[id].type);
  }
  return (r);
}

https://wiki.osdev.org/CPU_Registers_x86-64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants