Question:
In Assembly What Instruction moves data from storage (Say a hard Drive) to Memory?, and if possible can i get as to how?/why.?
Alejandro Peña
2018-06-21 04:21:09 UTC
In Assembly What Instruction moves data from storage (Say a hard Drive) to Memory?, and if possible can i get as to how?/why.?
Six answers:
Andy T
2018-06-22 02:06:42 UTC
On very old system without DMA or just gone without any Mastering hardware option; it would be a MOVE operation, or LOAD as one of them stated, I only read it theoretically by the time I had 8080 embedded MC practicals we were well into the GUI and protected access era.



Continue with the very old theme, it splits into RISC or CISC CPU instruction set, x86 is example of CISC, it would have memory-to--memory MOV so that would count as 1 instruction, but a pure RISC needed at least two steps to achieve that, MOV memory-to-cache then again in reverse to the target spot. HD access is done as a memory spot, or interrupt that deposit actual payload to designated memory if you hadn't caught on. The actual procedure is not known to me but it has to be many cycles to set up the parameters.



With modern DMA, CPU is not involved. But as I said I did not really dealt in Assembly but it is logical to assume CPU has to trigger North Bridge (or South?) for DMA ops. And today there's no such thing as pure CISC or pure RISC CPU sets.
?
2018-06-21 20:51:08 UTC
I at least know from my old class, I think LOAD brings it into memory from the register. I dunno, not too good with processors but I remember some.
husoski
2018-06-21 13:39:53 UTC
Most processors don't have an instruction that does this; but many computer systems do (or have done in the past.) The details vary quite a bit from on system to another, but in all cases, the movement of the data is only a one part of a longer series of operations. To read from a disk, for example, the processor is normally communicating with a disk controller that must be told which physical device to read from, where on the disk to start reading and how much data to read.



After an input operation is initiated, it usually takes some time before any data is available from the device. Physical disk operations may take several milliseconds, and a modern processor core can execute millions of instructions in that time. So, rather than have the processor wait for an operation to complete; the computer system provides a way for the controller to let the CPU know when input data is available.



Once data is available, there are a few different ways to get it out of the device controller's memory and into the processor's memory. (This is the data transfer part of the input operation.)



One is for the processor to read it, one byte (or possibly word) at a time through an I/O port. On most processors, this transfer is either an "IN" instruction that reads the value from an I/O port into a CPU register, or a load/move instruction that does the same thing but with the port mapped as a dedicated location in the memory address space. Either way, (IO port or memory-mapped port), this transfer is from the controller to a register rather than to memory. Multiple instructions are needed to read a block of input data into memory.



Another is for the system to implement "Direct Memory Access" (DMA), so that the controller can directly store the input data into the processor's memory. In this case, no processor instructions perform the data transfer. That's all done "in the background".



A third option, one that's widely used with graphics controllers, but also has been used with hard drives, is for the controller's entire input buffer to be "mapped" into the processor's memory address space. Then, when the operation is complete the processor can use ordinary data movement instructions to copy the data from the controller into an application's data buffer.



It's that last implementation method that allows the data input to be done in one CPU instruction; provided that the processor supports a block move instruction and the OS decides to use it.
amania_r
2018-06-21 08:20:19 UTC
As JazSinc says. Accessing devices is a privileged operation in most operating systems so you have to let the kernel do that via a system call. You can't just write a regular program to access devices.
2018-06-21 05:34:23 UTC
In the old MS-DOS days, that function was fulfilled by the Int 21h functions. Int 21h was the software interrupt you called to get DOS to perform a certain function. Almost all DOS functions were carried out through this interrupt. Each subfunction was carried out by first loading a specific value into the AH register, for example:



mov ah, 3dh

int 21h



This would call interrupt 21h, subfunction 3dh.
JazSinc
2018-06-21 05:14:31 UTC
There is no single instruction which does that.

Your assembly language program has to open a file by accessing the operating system.

Then it has to read the contents of the file, which again is a call to the operating system.



This can be complicated or simple depending on your operating system. I learned with PC-DOS 1.0 where it was absolutely crazy.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...