cvbvcb

title PrintFirstName
.model small
.stack
.data
.code

mov ax, 3 ;clears the screen
int 10h

mov ah, 2 ;print
mov dl, '?'
int 21h

mov ah, 1 ;input
int 21h

mov bh, al

mov ah, 2 ;print
mov dl, 0ah
int 21h

mov ah, 2 ;print
mov dl, 0dh
int 21h



mov ah, 2 ;print
mov dl, 0ah
int 21h

mov ah, 2 ;print
mov dl, 0dh
int 21h

mov ah, 2 ;print
mov dl, '?'
int 21h

mov ah, 1 ;input
int 21h

mov ch, al

mov ah, 2 ;print
mov dl, 0ah
int 21h

mov ah, 2 ;print
mov dl, 0dh
int 21h



mov ah, 2 ;print
mov dl, 0ah
int 21h

mov ah, 2 ;print
mov dl, 0dh
int 21h

sub bh, 30h
sub ch, 30h
add bh, ch
add bh, 30h

mov ah, 2 ;print
mov dl, bh
int 21h



mov ah, 4ch ;end of the program
int 21h
end
What's that supposed to do?

Also, add
mov ah, 0
int 0x16
at the end (waits for a key)

sub bh, 30h
sub ch, 30h
add bh, ch
add bh, 30h
is a little silly. That says bh += -48 + (ch -48) +48. Why not simply bh += ch -48?
@hamsterman
Yeah that's silly. I didn't mean to post this crappy code here, I was at school and I gotta save it fast (I forgot my thumb drive and I gotta get out of the room).

BTW it seems like you know something about ASM. Can you point me to some tutorials on the web? I can't find a good one. We're using TASM at school and it's my third day on ASM.
I know a little, but I'm afraid I can't help you much. I don't think I've ever seen a good tutorial. However to learn assembly mostly you just need a reference and some examples. And a good place to find examples is the disassembly of your C++ code.

edit: And why do you have lessons in summer? Don't you have summer vacation in Philippines?
Last edited on
Hmm I see, thanks anyway. I'm also been googling for a while with no luck.


And why do you have lessons in summer? Don't you have summer vacation in Philippines?
Sure we do have summer vacation, starts at 3rd week of March up to the 2nd week of June. Our country only have two seasons, rainy and summer. This June is going to be all rain. T T
http://www.intel.com/products/processor/manuals/index.htm

I've found this useful to get started: http://myw3b.net/blog/index.php/2009/10/assembly-for-c-programmers-1/
When you don't know how to do something, write it in C and examine the compiler output.
NASM makes it easy to interface with modern compilers. The Windows version can generate objects for both MinGW and VC++, and unlike GAS, its syntax isn't revolting. Nowadays, NASM is the assembler.
This is a good place to start -> http://www.phatcode.net/res/226/files/pcasm-book.pdf

Later, you can move on to this -> http://www.planetpdf.com/codecuts/pdfs/aoa.pdf
two seasons, rainy and summer.

Like England, except we have "cold" and "wet".

Edit: Actually it's sunny and warm outside right now, we always get the odd nice day.
Last edited on
@helios and m4ster r0shi
Thanks for the link. I will for sure read this tomorrow (it's late night and I'm tired already).


You know this assembly thing confuses me much. Most books and articles often mention something like "Intel Architecture" or "x86" or "x64" or "AMD64" which I really don't understand what they mean (it would be nice if some clears this up for me). At school, some computers there have AMD and some are Intel processors, we all use the same OS and TASM as our assembler and the output is all the same.

My class instructor said that in assembly, we are directly giving instruction to the CPU unlike languages like C++ or C. But isn't the OS giving instruction to the CPU, because the program runs under a certain OS and we see the ouput on the cmd.exe which is another program. whew o.O


chrisname wrote:
Like England, except we have "cold" and "wet".

Edit: Actually it's sunny and warm outside right now, we always get the odd nice day.
We also don't have winter or something like that, Philippines is a hot place except for some places like the city I'm in right now. This month of June is going to be all rain or even heavy rain. Everyone gets a free car wash.
x86 is the instruction set and architecture designed by Intel which both Intel and AMD implement, in the same way that Microsoft and GNU write implementations of C++. "IA-32" and "i386" are synonyms of "x86".
"x86-64", "x64", "AMD64", "EM64T", and "IA-32e", all refer to the instruction set that's the 64-bit extension of x86. This is what's included in such CPUs as Athlon64 and Core 2. Note that IA-64 is a different architecture altogether; namely, the Itanium.

What your instructor said is technically incorrect. In C and C++ you're also giving instructions directly to the CPU, it's just that you're doing it from a higher abstraction level. He would've been right if he had said "Python", because then you're giving instructions to the Python virtual machine/interpreter, which then gives instructions to the CPU.

The process of running a program on a multitasking OS looks something like this:
1. Kernel allocates stack, static, and code space for the new process.
2. Kernel loads program to memory.
3. Kernel allocates a time slice for the process and gives control to the program.
4. Program has exclusive control over the CPU. It may load registers, make system calls to allocate more memory, etc.
5. Once the time slice ends (time slices are very short in human terms), the kernel takes control back from the process, saves the CPU state (registers, flags, etc.) to memory, restores the CPU state and allocates a time slice for the next process, and gives control to it. This is known as a context switch. The CPU lets the kernel know when the time slice ends through interrupts; while a process has control, the kernel doesn't use any CPU time.
Note: The above pretends processes are single-threaded. In a multitasking system, time slices are given to threads, not to processes, and context switches occur between threads.
@helios
Thank you very much! I learned much from you.
Topic archived. No new replies allowed.