Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Programming with NASM / Re: Why do MUL and IMUL give the same output?
« Last post by fredericopissarra on October 13, 2019, 10:58:53 AM »
I still get the same output value of 0x8000 stored in AX. However, this is invalid, since both inputs are positive, and therefore the output is clearly also positive, but positive 0x8000 is an INVALID value for a 16bit signed integer. Why does the CPU actually complete this calculation, instead of throwing an error (which then would need to be handled by SEH, structured exception handling, in the program)?

It seems that with the CPU ignoring this error condition, MUL and IMUL operators are actually identical.
You are forgetting that MUL/IMUL results, in this case, are 32 bits values stored in DX:AX.
Using IMUL, 0x4000 times 2 is 0x00008000 (32 bits).

MUL/IMUL doesn't raise exceptions, they affect the flags (CF and OF - they have the same meaning: flagging overflow condition). Here's a simple test:
Code: [Select]
; mul.asm
bits  64

section .text

; int testmul( int *carry );
  global testmul
testmul:
  mov ecx,0x40000000
  mov eax,2
  imul ecx
  mov ecx,0
  setc cl
  mov [rdi],ecx
  ret
Code: [Select]
/* test.c */
#include <stdio.h>

extern int testmul( int * );

int main( void )
{
  int r, c;

  r = testmul(&c);

  printf( "result=%#x, carry=%d\n", r, c );
}
This will result in:
Code: [Select]
result=0x80000000, carry=1As it should!
12
Programming with NASM / Why do MUL and IMUL give the same output?
« Last post by ben321 on October 13, 2019, 04:17:03 AM »
Ok, so I made a simple Win32 program, and then observed the output of this program via OllyDbg.

If I do this with unsigned multiplying:
Code: [Select]
mov ax,0x4000
mov cx,0x0002
mul cx
AX receives the value 0x8000 (as I'd expect, as it is a valid value).

However if I change it to signed multiplying:
Code: [Select]
mov ax,0x4000
mov cx,0x0002
imul cx
I still get the same output value of 0x8000 stored in AX. However, this is invalid, since both inputs are positive, and therefore the output is clearly also positive, but positive 0x8000 is an INVALID value for a 16bit signed integer. Why does the CPU actually complete this calculation, instead of throwing an error (which then would need to be handled by SEH, structured exception handling, in the program)?

It seems that with the CPU ignoring this error condition, MUL and IMUL operators are actually identical.
13
Using NASM / Re: How does the test instruction work?
« Last post by fredericopissarra on October 10, 2019, 11:48:45 PM »
I was wondering how the test instruction works, I know it does almost the same thing as and.

The only difference is that "test" only sets the flags (you're primarily interested in the Zero Flag (ZF) here) while "and" sets the flags (ZF) as well as the destination operand.
Just a tiny correction... TEST is, indeed AND affecting only the flags, but ALL arithmetic/logic related flags are affected... ZF, SF and PF are set/reset depending on the result, and CF=OF=0. The AF flag is undefined.
14
Using NASM / Re: How does the test instruction work?
« Last post by JoyceTruitt on October 10, 2019, 02:44:16 PM »
An ordinance is informed for the enhancement of the goals for the humans. It is parked for the effectiveness of the writemypapers.org for all notified items for the humans. The chance is diffused for their forms for the brisk paces and all challenges for the humans. it is signed for the reforms for the manners for the punctuation for the targeted and all elements for the able men and women of the area of the west.
15
Programming with NASM / Re: IDE for asm
« Last post by RuudB on October 09, 2019, 10:12:28 AM »
I use PSPad, www.pspad.com/en/, because IMHO it quite easy to execute a batch file that has been linked to an extension. When wanting to assemble a source code, I press Ctrl-F9 and a batch file does the rest. No need at all to switch between windows.
I have tried Notepad++ because it is more well known, but I couldn't get it to work properly.
16
Programming with NASM / Re: NASM inserts an unwanted WAIT byte, why?
« Last post by RuudB on October 09, 2019, 10:04:01 AM »
I found the error: FINIT is something else than FNINIT.
I'm sorry for waisting you time.
17
Programming with NASM / Re: NASM inserts an unwanted WAIT byte, why?
« Last post by RuudB on October 09, 2019, 07:58:40 AM »
Just FYI:

I replaced the FINIT instruction by "db 0DBh, 0E3h" and the code is assembled fine now. The actual difference with the original BIOS is just one byte: the length of the keyboard buffer has been shortened. The other differences are most probably caused by using another assembler: if I disassemble the original BIOS I get the same source code, except this one byte.
18
Programming with NASM / NASM inserts an unwanted WAIT byte, why?
« Last post by RuudB on October 09, 2019, 07:00:52 AM »
Hello,

I'm busy disassembling a XT BIOS. I started disassembling it some where in the '90s using Sourcer. In 2014 I converted the source code to NASM. Then the board died... :(
Last month I got the same board with, seemingly, the same ROM (both say V2.30) but quite some bytes were different. In this case I used my own disassembler. If I assemble the one generated by my tool, NASM inserts an extra 09Bh byte before the only FINIT instruction in this BIOS. I have no idea why. Please have a look, maybe you see something.

The listing of the original source that compiles fine:
Code: [Select]
   600 0000036F 093E1000                or [Equipment],di
   601 00000373 B201                    mov dl,001h
   602 00000375 EC                      in al,dx
   603 00000376 240F                    and al,00Fh
   604 00000378 7505                    jne B_E37F
   605                                 
   606 0000037A 800E110010              or byte [M_0011],010h
   607                                  B_E37F: ; [E37F]
   608 0000037F DBE3                    fninit
   609 00000381 C606910000              mov byte [M_0091],000h
   610 00000386 D93E9000                fnstcw word [M_0090]
   611 0000038A 8A269100                mov ah,[M_0091]
   612 0000038E 80FC03                  cmp ah,003h
   613 00000391 7505                    jne B_E398
   614                                 
   615 00000393 800E100002              or byte [Equipment],002h
   616                                  B_E398: ; [E398]
   617 00000398 BAF703                  mov dx,003F7h
 

There is an EQU of course for all "M_xxxx" variables like:
Code: [Select]
    15                                  M_0011 equ 00011h

The listing of the new source that adds the WAIT at line 586:
Code: [Select]
   578 0000036F 093E1000                or [Equipment],di
   579 00000373 B201                    mov dl,01h
   580 00000375 EC                      in al,dx
   581 00000376 240F                    and al,0Fh
   582 00000378 7505                    jne B_E37F ; [E37F]
   583                                 
   584 0000037A 800E110010              or byte [0011h],10h
   585                                  B_E37F: ; [E37F]
   586 0000037F 9BDBE3                  finit
   587 00000382 C606910000              mov byte [0091h],00h
   588 00000387 D93E9000                fnstcw word [0090h]
   589 0000038B 8A269100                mov ah,[0091h]
   590 0000038F 80FC03                  cmp ah,03h
   591 00000392 7505                    jne B_E398 ; [E398]
   592                                 
   593 00000394 800E100002              or byte [Equipment],02h
   594                                  B_E398: ; [E398]
   595 00000399 BAF703                  mov dx,03F7h
I don't see why it could influence the behavior of NASM but just to be sure I replaced the used [xxxxh] variables here above by their M_ equivalents: it didn't change things.

Any info or help is welcome. Thanks in advance!

Kind regards, Ruud Baltissen
19
Programming with NASM / Re: How to send mail in NASM ??
« Last post by JoyceTruitt on October 08, 2019, 10:48:24 AM »
The topic of the argument is filled for manners for the field. The chance of the openness and time4writing reviews is done for the reforms for the citizens. The application is done for the transfer of the enhanced tips for the instruments for the future offers for all techniques for the humans.
20
Programming with NASM / Re: Problems with interrupt 1Ah
« Last post by yoran on October 07, 2019, 06:23:42 PM »
Sorry for the late reply but no this does not seem to work. I also switched the place of the function in memory and now the new function in that place seems to be having the problems (it just hangs the system).
Pages: 1 [2] 3 4 ... 10