Skip to the task
Layout
Back to classic view

You are looking at lesson 2. Your place is still lesson 11, task 1: fopen.

CHECKTask 21 of 23 · step 8: Extra: how does the CPU see it?

Where did the multiplication go?

Hover over the line with 100LL * 365 * 24 * 60 * 60. How many imul instructions do you find? Why?

Stuck?

None: every number is known in advance, so the compiler multiplied them itself and wrote the result, 3153600000. The same goes for sizeof (a ready 4, 8, 1) and 0.1 + 0.2. # ── topic 3 (lesson 40, step 9): practice/03/main.c ─────────────────

opened for this task

Extra · x86-64 · Intel syntax · Windows (MinGW GCC)

-O0 -O1

C source main.c

#include <limits.h>
#include <stdio.h>
#include "input.h"
int main(void) {
const int current_year = 2026;
int study_year = 1;
char group = 'A';
int birth_year = read_int("Year of birth: ");
int g1 = read_int("Grade 1: ");
int g2 = read_int("Grade 2: ");
int g3 = read_int("Grade 3: ");
double average = (g1 + g2 + g3) / 3.0;
int age = current_year - birth_year;
printf("Year of study: %d\n", study_year);
printf("Group: PI25%c\n", group);
printf("Age: %d years\n", age);
printf("Average: %.2f\n", average);
printf("In memory: int %zu B, double %zu B, char %zu B\n", sizeof study_year, sizeof average,
sizeof group);
printf("\n");
printf("Largest int: %d\n", INT_MAX);
long long century = 100LL * 365 * 24 * 60 * 60;
printf("100 years: %lld s\n", century);
printf("0.1 + 0.2 = %.17f\n", 0.1 + 0.2);
return 0;
}

x86-64 assembly -O0

.LC0:
.ascii "Year of birth: \0"
.LC1:
.ascii "Grade 1: \0"
.LC2:
.ascii "Grade 2: \0"
.LC3:
.ascii "Grade 3: \0"
.LC5:
.ascii "Year of study: %d\12\0"
.LC6:
.ascii "Group: PI25%c\12\0"
.LC7:
.ascii "Age: %d years\12\0"
.LC8:
.ascii "Average: %.2f\12\0"
.LC9:
.ascii "In memory: int %zu B, double %zu B, char %zu B\12\0"
.LC10:
.ascii "\12\0"
.LC11:
.ascii "Largest int: %d\12\0"
.LC12:
.ascii "100 years: %lld s\12\0"
.LC14:
.ascii "0.1 + 0.2 = %.17f\12\0"
main:
push rbp
mov rbp, rsp
sub rsp, 96
call __main
mov DWORD PTR -4[rbp], 2026
mov DWORD PTR -8[rbp], 1
mov BYTE PTR -9[rbp], 65
Note 1: A char is 1 byte (BYTE), and 'A' is just the number 65.
lea rcx, .LC0[rip]
call read_int
mov DWORD PTR -16[rbp], eax
Note 2: read_int's result comes back in eax and is stored in the variable.
lea rcx, .LC1[rip]
call read_int
mov DWORD PTR -20[rbp], eax
lea rcx, .LC2[rip]
call read_int
mov DWORD PTR -24[rbp], eax
lea rcx, .LC3[rip]
call read_int
mov DWORD PTR -28[rbp], eax
mov edx, DWORD PTR -20[rbp]
mov eax, DWORD PTR -24[rbp]
add edx, eax
mov eax, DWORD PTR -28[rbp]
add eax, edx
pxor xmm0, xmm0
cvtsi2sd xmm0, eax
movsd xmm1, QWORD PTR .LC4[rip]
divsd xmm0, xmm1
movsd QWORD PTR -40[rbp], xmm0
mov eax, DWORD PTR -4[rbp]
sub eax, DWORD PTR -16[rbp]
mov DWORD PTR -44[rbp], eax
mov eax, DWORD PTR -8[rbp]
mov edx, eax
lea rcx, .LC5[rip]
call printf
movsx eax, BYTE PTR -9[rbp]
mov edx, eax
lea rcx, .LC6[rip]
call printf
mov eax, DWORD PTR -44[rbp]
mov edx, eax
lea rcx, .LC7[rip]
call printf
movsd xmm0, QWORD PTR -40[rbp]
mov rax, QWORD PTR -40[rbp]
movupd xmm1, xmm0
mov rdx, rax
lea rcx, .LC8[rip]
call printf
mov r9d, 1
mov r8d, 8
Note 3: sizeof is already worked out: 4, 8 and 1 straight in the registers.
mov edx, 4
lea rcx, .LC9[rip]
call printf
lea rcx, .LC10[rip]
call printf
mov edx, 2147483647
lea rcx, .LC11[rip]
call printf
mov eax, 3153600000
Note 4: 100LL * 365 * 24 * 60 * 60: the compiler did the multiplying.
mov QWORD PTR -56[rbp], rax
mov rax, QWORD PTR -56[rbp]
mov rdx, rax
lea rcx, .LC12[rip]
call printf
mov rax, QWORD PTR .LC13[rip]
mov rdx, rax
movq xmm0, rdx
movupd xmm1, xmm0
mov rdx, rax
lea rcx, .LC14[rip]
call printf
mov eax, 0
leave
ret
.LC4:
.long 0
.long 1074266112
.LC13:
.long 858993460
.long 1070805811