0

I'm trying to make an assembly program that converts years to days.

This is my code:


section .data
    SYS_EXIT equ 60
    years db 100
    days dw 0
    yearToDay dw 365

section .text
_start:
    ; converting years to days
    mov ax, byte[age]           
    mul word[yearToMonth]
    mov word[days], ax
    mov word[days+2], dx        

exit_here:
    mov rax, SYS_EXIT
    xor rdi, rdi
    syscall

I get this error message whenever I try to run it: file.asm:15: error: mismatch in operand sizes

Isn't it that whenever the source variable (the multiplier) is in word-size, you should move the multiplicand to ax, and the product will be stored in dx:ax?

Brent
  • 45
  • 5
  • Yes, but `mov` requires both operands to be the same width. You're looking for `movzx eax, byte [age]`. It'd be easier to also zero-extend `yearToMonth` to a dword so you didn't have to deal with 16-bit halves of the result, or better, define it as an assemble-time constant like `yearToDay equ 365` so `imul eax, yearToDay` is equivalent to `imul eax, 365`. This is 64-bit code so you only need to work with narrow registers when that would be more efficient. Also, your `days` only has room for one word but you're storing two, overwriting `yearToDay`. – Peter Cordes Mar 09 '23 at 10:18

0 Answers0