how do i get the computer speed in Ghz in assembly

Dani AI

Generated

Short answer: there are two practical paths from assembly — ask the OS for a reported value, or read kernel-exposed CPU info — and which to use depends on whether you need the nominal (advertised) clock or the instantaneous per-core frequency. This expands on points raised by , and : existing tools show both approaches, and power-management can make a single “GHz” value misleading.

On Windows the easiest route is WMI: the Win32_Processor class exposes CurrentClockSpeed and MaxClockSpeed (values in MHz). From assembly you can either call COM/WMI (complex) or invoke a helper process and parse its output. Example quick check (outside assembly):

wmic cpu get CurrentClockSpeed,MaxClockSpeed

See Microsoft documentation for Win32_Processor for details: Win32_Processor (WMI).

On Linux look at the kernel interfaces. Older systems expose a sample in /proc/cpuinfo (cpu MHz in MHz); modern systems expose per-core runtime values under sysfs, e.g. /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq (value in kHz). Prefer the sysfs cpufreq files when present for instantaneous per-core numbers; fall back to /proc/cpuinfo if not. Kernel docs: proc(5) and cpufreq documentation.

Practical cautions and tips: reported values may be nominal or current depending on the source; per-core frequencies can differ; virtual machines may report host or synthetic values. Convert units carefully (MHz ÷ 1000 = GHz; kHz ÷ 1,000,000 = GHz). If you need tightly accurate, up-to-the-microsecond real frequency for short intervals, a timing-based measurement is the other option mentioned in the thread; for most tasks using WMI/sysfs is simpler and sufficient.

Recommended Answers

All 3 Replies

You will basically have to come up with a code to test the frequency of the processor, which is basically a while loop that counts the clocks within a time frame. To find the frequency of older processors such as the 80386 which does not have the RDTSC instruction, will be a bit more trivial. In all cases you will need to indentify the family of the processor with CPUID instruction to make results more accurate. So get creative because there is no instruction that will give you this frequency.

This little app might be usefull. although it also contains some Delphi, the core is written in assembly. 's another one.

Hi,

If your target CPU is using Intel SpeedStep technology or some kind of PST, ODCM technology then the speed will be varying over time and although you can access the adjusted speed too, the best and easiest way is to use the difference of RDTSC opcode's return value for a fixed amount of time.

Loren Soth

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.