So this week i decided to take a look at the Assembly language, watching some tutorials, reading some stuff. (tutorials on this page, on other pages and on youtube)
And as the forum rules does not prohibit me from ask beginner or "stupid" questions, Im going to ask some questions about the things i did not understand. I have tried googleing without the slightest of success.
Using the newest stable version of FASM and DOSBox (windows 7 x64)
I would appreciate if you could answer some or all of these question or tell me where i can find the answers by myself
How does "ORG" work?
When to use 16 bits? 32bits? 64bits? (pros vs cons?)
How to know which register to use (all general purpose registers good? the only thing that i should go after is how many bytes it can hold?)
30d = thirty decimal = 30 bytes long?
when/where to use "$"
0ah = /n?
differences between different assemblers? Recommendations?
when to use and what does "interrupt" do?
3 replies to this topic
#1
Posted 04 November 2011 - 02:52 PM
|
|
|
#2
Posted 04 November 2011 - 04:30 PM
I like NASM, as for the assemblers part.
ORG means "where, in memory, the program would be loaded," relative to the current base segment address. In 8086, and 8088, the base address = segment register value * 16
As for which registers to use where, the best register to use for pointers would be BX (8086 or 8088 - also a good habit, I think, on newer processors, but it's your choice for those).
This is because BX and BP are the registers that are most flexible about effective addressing. Related to this, the best index registers are SI and DI, because of the fact that they're the only ones that can be used as indexes in effective addresses (8086 or 8088).
The best data transfer/processing/arithmetic register(/s) would be the accumulator (AX/AL/AH).
So 'mov ax, [bx+si]' and 'mov ax, [bx+di]' and 'mov ax, [bp+si]' and etc., are all valid. You can also add immediate offsets to those register-using effective addresses, as in 'mov ax, [bx+si+8]' , etc.
About interrupts, the processor executes the currently-running program, and then something happens outside the processor that "interrupts" the processor from the program, and makes the processor go and see what's going on outside. Each piece of outside hardware has an interrupt number, and when that piece of hardware changes state or something, the processor goes to the interrupt reference table (in the 8086/8088 case the Interrupt Vector Table, or the IVT), and checks the entry for that interrupt number. The entry consists of an offset (for IVT, 16-bit address) and a segment (for IVT, 16-bit segment value; this * 16 + offset is where the processor would go to, to execute the interrupt-handling code), respectively.
Newer processors have this Interrupt Descriptor Table (IDT), which works differently, is more complex, and deals a lot with pointers. Despite all the complexity of the 386 and newer processors, however, the 32-bit registers, and register-use flexibility, would probably make up for all this complicated stuff.
ORG means "where, in memory, the program would be loaded," relative to the current base segment address. In 8086, and 8088, the base address = segment register value * 16
As for which registers to use where, the best register to use for pointers would be BX (8086 or 8088 - also a good habit, I think, on newer processors, but it's your choice for those).
This is because BX and BP are the registers that are most flexible about effective addressing. Related to this, the best index registers are SI and DI, because of the fact that they're the only ones that can be used as indexes in effective addresses (8086 or 8088).
The best data transfer/processing/arithmetic register(/s) would be the accumulator (AX/AL/AH).
So 'mov ax, [bx+si]' and 'mov ax, [bx+di]' and 'mov ax, [bp+si]' and etc., are all valid. You can also add immediate offsets to those register-using effective addresses, as in 'mov ax, [bx+si+8]' , etc.
About interrupts, the processor executes the currently-running program, and then something happens outside the processor that "interrupts" the processor from the program, and makes the processor go and see what's going on outside. Each piece of outside hardware has an interrupt number, and when that piece of hardware changes state or something, the processor goes to the interrupt reference table (in the 8086/8088 case the Interrupt Vector Table, or the IVT), and checks the entry for that interrupt number. The entry consists of an offset (for IVT, 16-bit address) and a segment (for IVT, 16-bit segment value; this * 16 + offset is where the processor would go to, to execute the interrupt-handling code), respectively.
Newer processors have this Interrupt Descriptor Table (IDT), which works differently, is more complex, and deals a lot with pointers. Despite all the complexity of the 386 and newer processors, however, the 32-bit registers, and register-use flexibility, would probably make up for all this complicated stuff.
#3
Posted 04 November 2011 - 04:39 PM
Thanks for the good answer (couldnt give rep though to the fact that i did it yesterday).
But i watched this tutorial, and he used BIT16 ORG100h, (hello world thingy) why x16? should everything for the new processors be done in x64 or 32? or does it still work well?
But i watched this tutorial, and he used BIT16 ORG100h, (hello world thingy) why x16? should everything for the new processors be done in x64 or 32? or does it still work well?
#4
Posted 04 November 2011 - 05:03 PM
All Intel-based computers start up in x86, 16-bit mode; if you do 'use32' or 'BITS 64' (NASM syntax), then your program would not work in 16-bit mode, and since not in 16-bit mode, it would also not work as a boot-loader, or for a MS-DOS command (.com) program, etc.
It is the operating system's job and responsibility to switch into 32-bit mode, before executing 32-bit code. I am not very familiar with 64-bit mode, and such, so I can't say much about that; if you're new to assembly, I would recommend not going into 64-bit stuff until you at least have a good grasp of 16- and 32-bit.
It is the operating system's job and responsibility to switch into 32-bit mode, before executing 32-bit code. I am not very familiar with 64-bit mode, and such, so I can't say much about that; if you're new to assembly, I would recommend not going into 64-bit stuff until you at least have a good grasp of 16- and 32-bit.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









