|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Feb 2006
Messaggi: 343
|
[C + Assembly] Null pointer assignment
Mi rendo conto che sto chiedendo cose davvero "vecchie", però mi fanno fare quello all'università quindi ci provo lo stesso. Allora per farla breve:
devo fare una procedura in Assembly che sia richiamabile da un programma C. Questa procedura deve contare i giorni a partire dal 01/01/2000 fino alla data passata come parametro, e restituirli come valore di ritorno. Io ho fatto tutto ma il problema è che quando faccio partire l'eseguibile, alla fine del programma mi scrive "Null pointer assignment". Il codice Assembly è questo (tagliando le parte dell'algoritmo che è corretto): Codice:
DEFAULT_YEAR EQU 2000
DEFAULT_MONTH EQU 1
DEFAULT_DAY EQU 1
DAYS_PER_YEAR EQU 365
PUBLIC _countdays
.MODEL small
.STACK
.DATA
DAYS_PER_MONTH DB 31,28,31,30,31,30,31,31,30,31,30,31
DAY DB ?
MONTH DB ?
YEAR DW ?
TOTAL_DAYS DW ?
.CODE
_countdays PROC NEAR
PUSH BP
MOV BP, SP
PUSH SI
; ...
; lettura parametro e calcolo giorni
; ...
MOV AX, TOTAL_DAYS ; valore di ritorno
POP SI
POP BP
RET
_countdays ENDP
END
Codice:
#include <stdio.h>
#include <stdlib.h>
/* Assembly procedure */
extern unsigned int countdays (char *date) ;
int main (void)
{
char date[10+1];
unsigned int total_days;
/* Code to set the italian keyboard, for Windows Vista and Windows 7 */
system("kb16 it");
/* Read the date */
printf ("Insert the date (dd/mm/yyyy): ");
scanf ("%s", date);
/* The date is assumed to be correct, so count days with the assembly procedure */
total_days = countdays (date) ;
/* Print the number of days */
printf ("\nTotal days from 01/01/2000 to %s: %u\n\n", date, total_days);
system("pause");
return 0;
}
Screen errore:
__________________
Portatile Asus ROG Strix GL502VSK - Core i7-7700HQ @ 2.8GHz (Turbo 3.8GHz) - 16Gb RAM DDR4-2400 (2x8Gb) - Nvidia GeForce GTX 1070 8Gb - Schermo 120Hz G-SYNC - SSD Samsung 960 PRO NVMe 512Gb - HDD 7200RPM 1Tb "Defeat is not the worst of failures. Not to have tried is the true failure." |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: May 2008
Messaggi: 533
|
■
Ultima modifica di rеpne scasb : 18-06-2012 alle 17:13. Motivo: Chiarimento su compilatore C |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:19.




















