untio 36 Light Poster

Hi,
Ancient Dragon, you have detected some errors, but, forgive me if I am wrong, in line 2:
"first: "
Is a literal string that contains the name of a variable, but it is not the variable.
Please, forgive my mistakes.

untio 36 Light Poster

Hi,

I am not a C++ expert, but I think that when you call scanf you must pass a pointer. The problem is that first is a pointer to char (that is the right parameter), but you are passing a pointer to pointer to char.

When you call scanf to get a string you should not use &. The name of the array is itself a pointer.

Cheers.

untio 36 Light Poster

Hi,
In 32 bits systems, there was emulation to 16 bits code.
In 64 bits systems, there is emulation to 32 bits code, but they do not support 16 bits programs.
If you want to know more about this emulation search in google "wow" (windows on windows).
There are three solutions:
1. You can install an emulator like VirtualBox and create a 32 bits virtual machine. To do this you need a 32 bits instalation disk. The virtual 32 bits system will emulate 16 bits machine when needed.
2. You can use an emulator to emulate a 16 bits machine. You need the instalation disks and a way to install them.
3. You use DosBox. It is the easier solution, I think.

Cheers.

untio 36 Light Poster

Hi,
I do not know your level of assembly in 32 bits on windows.
I have written a Hello world program and can be compiled using the file build.bat of the masm32 package. May be it surprise you.

This is the code:

.486
.model flat,stdcall
option casemap:none

include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib


.data
    bbbb db "is wonderful", 0
        aaaa db "Assembly",0
.code


inicio:
    invoke MessageBox, NULL, addr bbbb, addr aaaa, MB_OK
    invoke ExitProcess, 0
end inicio

You need to understand that interrupts are forbiden and you must call windows api functions.

Registers are named preceding an "E" to the msdos part: EAX, EBX, ECX, etc.
The low word can be accessed with the msdos name. AX is the low word of EAX. And AH is the high byte of AX and AL is the low byte of AX (and of EAX).

The good news are that in the model flat all segment registers point to the same segment of 4GB. You do not need to refer to them in the most cases.

Cheers.

untio 36 Light Poster

Hi,
May be, os.system() is useful to you:
Click Here
Forgive me if I am wrong.

untio 36 Light Poster

Hi,
In the x86 processors it is not possible to do an operation between two adresses of memory. Simply it is impossible to copy directly from memory to memory. You need to copy to a register and copy the content of the register to the target address.
Cheers.

untio 36 Light Poster

If you have, for instance, in eax the value 2 and you add 0 to eax, eax will contain 2. Add zero has no effect.
If you want a register with a zero value, you can do it with 'mov eax, 0' or, as prefered by some programers: 'xor eax, eax'.

untio 36 Light Poster

Hi,
You can remove lines from 25 to 29 without any doubt.

untio 36 Light Poster

Hi,
What is the reason to add zero to the registers. This has no effect. Why?.
The rest of the code is very good.

Best regards

untio 36 Light Poster

Hi,
You need a complete course on assembly language.
You try to declare a variable inside the text section. Text section is for machine instructions.
If you must reserve space for variables, you can achieve it in:
data section if the variable is initialized.
bss section if the variable in not initialized.
In this case data will reside in the bss section. Do reserve space in the bss section, nasm have this method:

[section .bss]
	 K : resd 1
	 D : resd 1

before the text section
The 'd' means dword, four bytes.
In assembly language there is not a ':=' operator. If you need to assign a value, you can do it like 'mov eax, ebx'. It will copy the value inside ebx into eax.
Another big error is in the imul operands. imul multiplies with sign the operand by eax and put the result in edx:eax.

mov edx, 0
mov eax, 2
mov ebx, 3
imul ebx

edx contains 0 and eax contains 6.
A bigger error is:

sub K, 1

In x86 it is not possible to operate with two places in memory. The assembler will complain with a message: invalid combination of opcode and operands.
You must write something like this:

mov eax, K
sub eax, 1
mov K, eax

And, finally, do you wish to try this code - with nasm syntax-:

;;
	;; Register usage:
	;; EAX Sum
	;; ECX Original value of …
untio 36 Light Poster

Hi,
The problem is that 'add si, 1' modifies the flags. You can test if bh is equal to zero after adding 1 to si and your code will work right.

;cmp bh, 0 - Remove this line
add di, 1 ; Flags are affected.
add si, 1 ; Flags are affected.
cmp bh, 0 ; - Add this line
jne CmpString

I hope that this can be useful.