Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


NUCLEAR RABBIT

Member Since 12 Apr 2006
Offline Last Active Mar 04 2015 09:34 PM

Topics I've Started

MASM Assembly bug [SOLVED]

07 February 2015 - 05:15 PM

Hello,

 

So I was working on a very lame application to practice using assembly and I got the application working and doing what I want it to, but at the application endpoint it prints out the welcome greeting string and I only have one section that calls that greet (in the beginning). Does anyone know why this could be happening? Any help is appreciated!

 

PS - I took a screenshot of the output for you guys to see what I mean.

 

age.asm:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                              ;
;   Name: Brandon                              ;
;   Date: 2/6/2015                             ;
;   Desc: Simply asks the user for their age   ;
;         and then greets the user with the    ;
;         age value they entered in            ;
;                                              ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.model small
.stack 100h

.data
age db ?
welcome_greet db 'Welcome to the GREATEST application EVER!!!', 10, 13, '$'
age_prompt db 'Please enter your age: ', '$'
result_prompt db 10, 13, 'The age you entered is: ', '$'
exit_prompt db 'Goodbye, hope you enjoyed this AMAZING application!', 10, 13, '$'

.code
main proc
mov AX, @DATA              ; must do everytime
mov DS, AX                 ; must also do everytime as well

lea DX, welcome_greet
mov AH, 9h                 ; DOS command to print a string
int 21h

lea DX, age_prompt         ; prompts the user for their age
mov AH, 9h
int 21h

mov AH, 1h                 ; 1h is a DOS command to read in a char
int 21h
mov AGE, AL              

lea DX, result_prompt      ; prints the result message
mov AH, 9h
int 21h

lea DX, AGE                ; prints resulting age
mov AH, 9h
int 21h

mov AH, 04ch               ; exits the DOS application
int 21h

main ENDp
end main


MASM Assembly Help!

06 February 2015 - 06:35 PM

Hello,

 

So I am currently learning MASM 8086 Assembly right now I am have trouble with an application I am attempting to mess around with and create for practice. Not sure what the errors I am getting mean (I am extremely new to assembly). Can someone please help me understand what I am doing wrong? I have attached the screenshot of the error messages and the source code. ANY help would be greatly appreciated!

 

age.asm

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                              ;
;   Name: Brandon                              ;
;   Date: 2/6/2015                             ;
;   Desc: Simply asks the user for their age   ;
;         and then greets the user with the    ;
;         age value they entered in            ;
;                                              ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.model small
.stack 100h

.data
age db ?
welcome_greet db 'Welcome to the GREATEST application EVER!!!', 10, 13, '$'
age_prompt db 'Please enter your age: ', 10, 13, '$'
result_prompt db 'The age you entered is: ', 10, 13, '$'
exit_prompt db 'Goodbye, hope you enjoyed this AMAZING application!', 10, 13, '$'

.code
main proc
mov AX, @DATA              ; must do everytime
mov DS, AX                 ; must also do everytime as well

lea DX, welcome_greet      ; loads the welcome_greet into the DX registery
mov AH, 9h                 ; DOS command to print a string
int 21h

lea DX, age_prompt
move AH, 9h
int 21h

move AH, 1h                ; 1h is a DOS command to read in a char
int 21h
sub AL, '0'                ; converts to an integar
move AGE, AL               ; saves the value into AGE

move AH, 9h
lea DX, result_prompt
int 21h

move AH, 2h                ; prints a char
int 21h

move AH, 04ch              ; exits the DOS application
int 21h

main endp
end main

Also, I have a few questions about the code I have. Is the DX registery only used for loading output messages into?

lea DX, welcome_greet      ; loads the welcome_greet into the DX registery
mov AH, 9h                 ; DOS command to print a string
int 21h

Like I said, I am extreme beginner to assembly so any explinations/corrections would be awesome! biggrin.png


C++ & SDL Help Needed!

02 February 2015 - 10:05 PM

Hello,

 

I have been trying for the last few days to get SDLworking on my machine (OS X) so I can start working towards learning to create a 2D platformer, but I am having a harder time I believe it should be to get it working correctly...I got the templates working and it compiles fine, but when I try running it, nothing happens and this is what my compiler says it cannot load something. Has anyone had this issue before or maybe might know what I am missing? PLEASE, Any help would be greatly appreciated!!!

 

I attached a screenshot of what my compiler does when I run the template program.

// ============================================================================
// [Include Section]
// ============================================================================
#include "SDL2/SDL.h"

// ============================================================================
// [SdlApplication]
// ============================================================================
#define APPTITLE "SDL Template Program"
// SdlApplication is nothing more than thin wrapper to SDL library. You need
// just to instantiate it and call run() to enter the SDL event loop.
struct SdlApplication
{
	SdlApplication();
	~SdlApplication();
	
	// Application state (just convenience instead of 0, 1, ...).
	enum APP_STATE
	{
		APP_OK = 0,
		APP_FAILED = 1
	};
	
	// Initialize application, called by run(), don't call manually.
	int init(int width, int height);
	
	// Destroy application, called by destructor, don't call manually.
	void destroy();
	
	// Run application, called by your code.
	int run(int width, int height);
	
	// Called to process SDL event.
	void onEvent(SDL_Event* ev);
	
	// Called to render content into buffer.
	void Render();
	
	// Whether the application is in event loop.
	bool _running;
	SDL_Window *win;
	SDL_Renderer *renderer;
};

SdlApplication::SdlApplication() :
_running(false)
{
}

SdlApplication::~SdlApplication()
{
	destroy();
}

int SdlApplication::init(int width, int height)
{
	// Initialize the SDL library.
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
	{
		fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
		return APP_FAILED;
	}
	
	win = SDL_CreateWindow(APPTITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
	renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	
	// Success.
	return APP_OK;
}

void SdlApplication::destroy()
{
	if (win)
	{
		SDL_DestroyWindow(win);
		SDL_DestroyRenderer(renderer);
		SDL_Quit();
	}
}

int SdlApplication::run(int width, int height)
{
	// Initialize application.
	int state = init(width, height);
	if (state != APP_OK) return state;
	
	// Enter to the SDL event loop.
	SDL_Event ev;
	_running = true;
	
	while (SDL_WaitEvent(&ev))
	{
		onEvent(&ev);
		Render();
		
		if (_running == false)
		{
			break;
		}
	}
	
	return APP_OK;
}

void SdlApplication::onEvent(SDL_Event* ev)
{
	switch (ev->type)
	{
		case SDL_QUIT:
			_running = false;
			break;
			
		case SDL_KEYDOWN:
		{
			if (ev->key.keysym.sym == SDLK_ESCAPE)
			{
				_running = false;
			}
		}
	}
}

void SdlApplication::Render()
{
	SDL_Rect r;
	int w,h;
	SDL_GetWindowSize(win, &w, &h);
	
	r.w = 200;
	r.h = 200;
	r.x = w/2-(r.w/2);
	r.y = h/2-(r.h/2);
	
	
	//
	SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0, 0xff);
	SDL_RenderClear(renderer);
	
	SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0, 0xff);
	SDL_RenderFillRect(renderer, &r);
	SDL_RenderPresent(renderer);
}


// ============================================================================
// [Entry-Point]
// ============================================================================

int main(int argc, char* argv[])
{
	SdlApplication app;
	return app.run(640, 480);
}

Polymorphism and Interfaces in Java

07 October 2014 - 02:23 PM

Hello,

 

So I recently learned about Interfaces and thought I had a good grasp, but I'm not sure why this example does what it does. It creates an interface object and assign it to an ArrayQueue<T>() object. Why not just write it as an ArrayQueue object to begin with, is there an advantage? I think my question relates more to polymorphism maybe, but I also thought that interfaces aren't objects that are initialized, just implemented from in another class.

 

Can anyone help clear the air? I would really appreciate any help! huh.png


Writing/Reading from files help needed! (C Programming)

21 May 2014 - 05:13 PM

hello, I am trying to write a program that makes 10 empty entries in my file, updating the first 3, and then asking the user which one to erase back to a blank entry, and then reprints the file contents again with the entry deleted. It seems to work okay ONLY if you delete the first entry, if you try to delete the 2nd or 3rd, the output goes all crazy! Any help would be greatly appreciated! :(

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

typedef struct person {
    char first_name[15];
    char last_name[15];
    char age[4];
    int accNum;
} Person;

int main(int argc, char * argv[])
{
    FILE * file = fopen("/Users/MYNAME/Desktop/person.txt", "r+");
    
    Person blankEntry = {"No First Name", "No Last Name", "0", 0};
    Person person1 = blankEntry;
    
    printf("Records:\n");
    for(int i = 1; i <= 10; i++) {
        fwrite(blankEntry.first_name, 1, sizeof(blankEntry.first_name), file);
        fwrite(blankEntry.last_name, 1, sizeof(blankEntry.last_name), file);
        fwrite(blankEntry.age, 1, sizeof(blankEntry.age), file);
        fprintf(file, "%d", i);
        
        printf("%d. %s\t\t\t%10s%10s\n", i, blankEntry.first_name, blankEntry.last_name, blankEntry.age);
    }
    
    printf("\n\nUpdating Record:\n");
    fseek(file, SEEK_SET, 0);
    for(int i = 1; i <= 3; i++) {
        printf("Enter in first name, last name, and age: ");
        scanf("%s %s %s", person1.first_name, person1.last_name, person1.age);
        
        fwrite(person1.first_name, 1, sizeof(person1.first_name), file);
        fwrite(person1.last_name, 1, sizeof(person1.last_name), file);
        fwrite(person1.age, 1, sizeof(person1.age), file);
        fprintf(file, "%d", i);
    }
    
    printf("\n\nRecords:\n");
    printf("First Name:\t\tLast Name:\t\tAge:\n");
    fseek(file, SEEK_SET, 0);
    for(int i = 1; i <= 10; i++) {
        fread(person1.first_name, 1, sizeof(person1.first_name), file);
        fread(person1.last_name, 1, sizeof(person1.last_name), file);
        fread(person1.age, 1, sizeof(person1.age), file);
        fscanf(file, "%d", &person1.accNum);
        
        printf("%i. %s\t\t%10s%10s\n", person1.accNum, person1.first_name, person1.last_name, person1.age);
    }
    
    int deleteKey;
    printf("\n\nEnter in account number to delete: ");
    scanf("%i", &deleteKey);
    
    fseek(file, (deleteKey - 1) * sizeof(struct person), SEEK_SET);
    fwrite(person1.first_name, 1, sizeof(person1.first_name), file);
    fwrite(person1.last_name, 1, sizeof(person1.last_name), file);
    fwrite(person1.age, 1, sizeof(person1.age), file);
    //fwrite(&blankEntry, sizeof(struct person), 1, file);
    
    printf("\n\nRecords:\n");
    printf("First Name:\t\tLast Name:\t\tAge:\n");
    fseek(file, SEEK_SET, 0);
    for(int i = 1; i <= 10; i++) {
        fread(person1.first_name, 1, sizeof(person1.first_name), file);
        fread(person1.last_name, 1, sizeof(person1.last_name), file);
        fread(person1.age, 1, sizeof(person1.age), file);
        fscanf(file, "%d", &person1.accNum);
        
        printf("%i. %s\t\t%10s%10s\n", person1.accNum, person1.first_name, person1.last_name, person1.age);
    }
    
    fclose(file);
    
    return 0;
}

PARTNERS