I want the computer to analyse what I have written and print the number of asterisks corresponding to the number inputted. I can only manage a piece of code that can read what I have inputted. I can't use arrays but can use loop instructions like jnz and conditional instructions like cmp.
What I have tried:
This is the code I have tried so far:
#include "stdafx.h"
#include <stdlib.h>
void printChar(char c);
void printStr(char *strAddr);
void printInt(int someInt);
//**************************************************************************//
// Variables defined. //
//**************************************************************************//
int numItems;
int *items; // Pointer to the items
int anItem;
int wmain(int argc, _TCHAR* argv[])
{
items = (int *)malloc(1000);
numItems = 0;
do
{
printf("Enter item %d (0 means end of data): ", numItems + 1);
scanf("%d", &anItem);
items[numItems] = anItem;
numItems++;
} while (anItem != 0);
//**********************************************************************//
// Into assembler. //
//**********************************************************************//
__asm
{
jmp finish
printNewLine:
push '\r' // Two lines to print a char.
call printChar
push '\n' // Two lines to print another char.
call printChar
ret
finish: // Do nothing
}
//**********************************************************************//
// Out of assembler. //
//**********************************************************************//
printf("press enter to quit\n");
char dummy[10]; //Just in case several keys in buffer
scanf("%c", dummy); //pause.
scanf("%c", dummy); //pause. And once more. Something weird going on.
}
//**********************************************************************//
// Prints a single character. //
// Push the char to be printed onto the stack; a First In Last Out //
// data structure. Remember, unlike C#, a char here is 1 byte in size. //
// //
// Parameters in: Push a single char onto the stack, as above. //
// Returns: Nothing. //
// Other issues: Does it preserve CPU registers eax, ebx, ecx, edx, //
// esi, edi etc.? No idea (it takes us into "C", so //
// assume not. //
//**********************************************************************//
void printChar(char c)
{
printf("%c", c); //%c means as a char
} // we don't seee the "ret" instruction unless you view the ".cod" listing
// in the "debug" folder.
//**********************************************************************//
// Print a whole string, which must end with a zero byte. //
// it takes one parameter, which is the start address of the string. //
//**********************************************************************//
void printStr(char *strAddr)
{
printf("%s", strAddr);
} // we don't seee the "ret" instruction unless you view the ".cod" listing
// in the "debug" folder.
//**********************************************************************//
// Prints a single integer . //
// Push the integer to be printed onto the stack; a First In Last Out //
// data structure. Remember, an integer here is 4 bytes in size. //
// //
// Parameters in: push a single integer onto the stack, as above. //
// Returns: Nothing. //
// Other issues: Does it preserve CPU registers eax, ebx, ecx, edx, //
// esi, edi etc.? No idea (it takes us into "C", so //
// assume not. //
//**********************************************************************//
void printInt(int someInt)
{
printf("%d", someInt);
}